pt kill commonly used to kill process parameters introduced

  • 2021-01-02 22:01:24
  • OfStack

pt-kill is a good kill MySQL connection tool. It is the first part of percona toolkit. When the maximum number of connections is exceeded due to too many idle connections and the load on mysql is high due to some problematic sql, the main purpose of this tool is to drop one of the connections.

1. According to user kill
/usr/bin/pt-kill --busy-time 15 --match-user="dbUSER1 | dbUSER2,..." --victim all --interval 1 --kill --daemonize --pid=/tmp/ptkill.pid --print --log=/home/pt-kill.log
Note: the test kills threads by user. Note -- match-user multiple users are separated by |.


2. Click query source host kill
/usr/bin/pt-kill --busy-time 15 --match-host="192.168.10.10 | 192.168.10.11" --victim all --interval 1 --kill --daemonize --pid=/tmp/ptkill.pid --print --log=/home/pt-kill.log
--ignore-host / --match-host

Note: the test kills threads by source host. Note -- match-host multiple host are separated by |.


3. Press the command kill
/usr/bin/pt-kill --busy-time 15 --match-command="query | Execute" --victim all --interval 1 --kill --daemonize --pid=/tmp/ptkill.pid --print --log=/home/pt-kill.log
/usr/bin/pt-kill --busy-time 15 --ignore-command="sleep | binlogdump" --victim all --interval 1 --kill --daemonize --pid=/tmp/ptkill.pid --print --log=/home/pt-kill.log

Note: The test kills the thread by pressing command. Note that the contents of command 1 must match the case strictly, otherwise the thread will not be killed. Note - match-command multiple command are separated by |, otherwise it will fail.
(command: Query, Sleep, Binlog Dump, Connect, Delayed insert, Execute, Fetch, Init DB, Kill, Processlist, Quit stmt, Table Dump)


4. Press the state kill
/usr/bin/pt-kill --busy-time 15 --match-state="Locked | Sending data" --victim all --interval 1 --kill --daemonize --pid=/tmp/ptkill.pid --print --log=/home/pt-kill.log
Note: The test kills the thread by pressing state. Note that the contents of state 1 must match the case strictly, otherwise the thread will not be killed. Note - match-state multiple state are separated by |, otherwise it will fail.
(state types are: Locked, login, copy table, Copying to tmp table tmp on on table, Sending data, Sorting for order, Sorting result, Table lock, Updating)


5. Press info keyword kill
/usr/bin/pt-kill --busy-time 15 --match-info="SELECT | DELETE" --victim all --interval 1 --kill --daemonize --pid=/tmp/ptkill.pid --print --log=/home/pt-kill.log
Note: The test kills the thread by pressing info. Note that the contents of info 1 must match the case strictly, otherwise the thread will not be killed. Note - match-info multiple info are separated by |, otherwise it will fail.
--ignore-info / --match-info
(info can use select, update, insert, delete for matching, and can use "|" for multiple matching, such as "select|SELECT|delete|DELETE|update|UPDATE"


6. Click on access dbname kill
/usr/bin/pt-kill --busy-time 15 --match-db="db1 | db2" --victim all --interval 1 --kill --daemonize --pid=/tmp/ptkill.pid --print --log=/home/pt-kill.log
--ignore-db / --match-db
Note: The test kills the thread by pressing db. Note that the contents of db 1 must match the case strictly, otherwise the thread will not be killed. Note - match-db multiple db are separated by |, otherwise it will fail.


Other: Action:
--kill kills the connection and exits
kill-query only kills the statement executed by the connection, but the thread is not terminated


Related articles: