Not the answer you need?
Register and ask your own question!

pt-kill seems to ignore options

dmurraydmurray Current User Role Novice
I'm not sure if I'm using it wrong, but right now I'm using pt-kill 3.2.0 with MariaDB 10.3.23 on Ubuntu and it seems to indiscriminately kill any running query. Here's what I'm using from the command line, the goal is to kill queries run by 'username' that have been running for at least 5 minutes:
/usr/bin/pt-kill --busy-time 300 --match-user username --kill --print --pid=/var/run/ --interval=5 --defaults-file=/root/.my.cnf --log=/var/log/ptkill.log
And here's an example of the output I'm getting:
# 2020-06-26T18:01:24 KILL 18754 (Sleep 0 sec) NULL
Am I missing something obvious or is pt-kill definitely not working as expected here?


  • yves.trudeauyves.trudeau Percona Percona Staff Role
    you'll find this: "pt-kill will kill all the queries matching ANY of the specified criteria (logical OR).".  What you have is "kill any query running for more than 300s OR any query from username".  You need a custom filter,  but the following in a file:

    my $event_ok; if (($event->{Time} > 300) && ($event->{User} == 'username')) { $event_ok=1; } else { $event_ok=0; } $event_ok

    The above example is untested but should work.  The documentation is a bit weak, I'll submit a ticket for that.  $event is provided by pt-kill is essentially the output of "show full processlist" with fetchall_arrayref.

  • yves.trudeauyves.trudeau Percona Percona Staff Role
    So, I actually tested the filter,  the filter needs to be:
    ~# cat /tmp/filter.txt
    my $event_ok;
    if (($event->{Time} > 300) && ($event->{User} eq 'username'))
    { $event_ok=1; }
    else { $event_ok=0; }
    return $event_ok
    and the pt-kill invocation:
    pt-kill --filter /tmp/filter.txt --match-user=username --kill-busy-commands 'Query|Execute' --print --kill --interval=5

  • dmurraydmurray Current User Role Novice
    Thanks heaps! This looks like it works now. I had to add "(defined $event->{Time})" as an additional condition to the if statement to get around "InnoDB purge worker" queries appearing in my processlist with a Time of NULL which caused "Use of uninitialized value in numeric gt (>) at (eval 37) line 2." to keep appearing, and it seems like --kill-busy-commands were being ignored as it still killed stuff running as "Sleep", but I should be able to modify that filter a bit more to get it to catch them properly there.

Sign In or Register to comment.

MySQL, InnoDB, MariaDB and MongoDB are trademarks of their respective owners.
Copyright ©2005 - 2020 Percona LLC. All rights reserved.