下载地址
PT-KILL
参数详解
| 项目 | 参数 | 含义 |
|---|---|---|
| 常用参数 | —host | 主机 |
| —port | 端口号 | |
| —socket | socket文件 | |
| —user | 用户 | |
| —password | 密码 | |
| —database | 连接的库 | |
| —daemonize | 后台运行 | |
| —interval | 查询频率,如果使用了—busy-time参数,此值默认为30s,如果命令行中此值也被定义,使用定义的值。 | |
| —log | 当后台运行的时候,打印输出到此参数指定的文件中 | |
| 匹配参数 | —busy-time | 匹配运行时间已长于此时间的查询。 查询必须处于Command = Query状态 |
| —idle-time | 匹配闲置/睡眠时间长于此时间的查询。 查询必须处于Command = Sleep状态。 | |
| —victim | 匹配过滤后,此选项指定的匹配查询将被终止,可选命令值为: oldest:只 KILL 时间最久的查询 all:KILL 所有匹配到的查询 all-but-oldest:保留时间最久的查询,其他的 KIll 默认值为 oldest。 |
|
| —match-command | 匹配指定命令类型的查询。 可用命令值为: Query Sleep Binlog Dump Connect Delayed insert Execute Fetch Init DB Kill Prepare Processlist Quit Reset stmt Table Dump |
|
| —match-all | 匹配所有不被忽略的查询。 | |
| —match-info | 匹配 INFO 信息符合的查询 | |
| —match-db | 仅匹配指定数据库中的查询 | |
| —match-host | 仅匹配指定主机上查询 | |
| —match-state | 仅匹配指定状态的查询,可用命令值为: Locked login copy to tmp table Copying to tmp table Copying to tmp table on disk Creating tmp table executing Reading from net Sending data Sorting for order Sorting result Table lock Updating |
|
| —match-user | 仅匹配指定用户的查询 | |
| —ignore-command | 忽略指定类型命令的查询 | |
| —ignore-db | 忽略指定库的查询 | |
| —ignore-host | 忽略指定主机的查询 | |
| —ignore-state | 忽略指定状态的查询 | |
| —ignore-user | 忽略指定用户的查询 | |
| 动作参数 | —execute-command | 查询匹配时执行此命令 |
| —kill | 杀死匹配到的查询的进程 | |
| —kill-query | 终止匹配到的查询,而不断开连接 | |
| 打印匹配到的查询而并不杀死查询。 想要打印并杀死匹配到 的查询时,请同时指定—kill和 —print 参数。 |
||
| 其他参数 | —log-dsn | 存储被 kill 的查询记录到指定的DSN中。 相关参数: A:字符编码 D:数据库 h:host p:passwd P:port S:socket u:user T:table |
| —create-log-table | 这个参数用于配合—log-dsn参数,自动创建默认的表结构来存储 kill 记录。 | |
| —config | 从指定的conf文件中加载选项参数,用于保存敏感信息。如果指定,则它必须是命令行上的第一个选项 | |
| —run-time | 指定运行时间,默认 pt-kill 是一直持续运行的,指定该参数后,到达指定的时间后进程将会退出。 | |
| —sentinel | 默认值为/tmp/pt-kill-sentinel,如果此文件存在,则退出 pt-kill 进程。 | |
| —stop | 通过创建—sentinel文件,来退出所有指定了—sentinel参数的 pt-kill 进程。 | |
| —wait-after-kill | 杀死查询后等待,然后再寻找更多要杀死的查询。目的是使被阻塞的查询有机会执行。 | |
| —wait-before-kill | 在删除查询之前等待。这样做的目的是让“ — execute-command”有机会查看匹配的查询,并在结束之前收集其他 MySQL 或系统信息。 |
使用范例
# 每隔10s打印所有执行时间大于15秒的查询。[root@test-mysql ~]# pt-kill --host=192.168.0.77 --port=3306 --user=root --password=744123 --busy-time 15 --victim all --interval 10 --print# 后台运行pt-kill,打印log到/tmp/pt-kill.log文件中。[root@test-mysql ~]# pt-kill --host=192.168.0.77 --port=3306 --user=root --password=744123 --busy-time 15 --victim all --interval 10 --daemonize --print --log=/tmp/pt-kill.log# 打印日志并kill 进程。[root@test-mysql ~]# pt-kill --host=192.168.0.77 --port=3306 --user=root --password=744123 --busy-time 15 --victim all --interval 10 --daemonize --print --log=/tmp/pt-kill.log --kill# 打印并 kill 用户为 USER1 或者 USER2 执行的并且时间大于15秒的查询。[root@test-mysql ~]# pt-kill --host=192.168.0.77 --port=3306 --user=root --password=744123 --busy-time 15 --match-user="USER1 | USER2" --victim all --interval 10 --daemonize --print --log=/tmp/pt-kill.log# 使用 conf 文件保存敏感信息,或者将通用的设置写进去。[root@test-mysql ~]# cat pt-kill.confhost=192.168.0.77port=3306user=rootpassword=744123victim=allinterval=10[root@test-mysql ~]# pt-kill --config pt-kill.conf --busy-time 15 --match-user="USER1 | USER2" --daemonize --print --log=/tmp/pt-kill.log# 将 kill 查询的记录存储到数据库中[root@test-mysql ~]# pt-kill --config pt-kill.conf --log-dsn D=hellodb,t=ptkill_log --create-log-table --busy-time 15 --match-user="USER1 | USER2" --daemonize
