【Mysql】pt工具之-pt-kill
pt-kill
概述
從show processlist 中獲取滿足條件的連線或者從包含show processlist的檔案中讀取滿足條件的連線並列印或者殺掉或者執行其他操作,這個工具在工作中實用性很高,當伺服器連線出現異常後第一想到的就是pt-kill,自己寫一個指令碼也可以,但是功能還是沒有pt-kill強大;
常用功能介紹
-
- [root@hostnfsd :/root]$ pt-kill --defaults-file=/data/mydata/my_3307.cnf -uroot -p`cat /etc/sqlpass` --busy-time 60 --kill --victims all --interval 10 每隔10s 殺掉處於runnning狀態超過60s的連線數;
- [root@hostnfsd :/root]$ pt-kill --defaults-file=/data/mydata/my_3307.cnf -uroot -p`cat /etc/sqlpass` --match-command Sleep --kill --victims all --interval 10 每隔10s 殺掉處於sleep狀態的連線數;
- [root@hostnfsd :/root]$ pt-kill --defaults-file=/data/mydata/my_3307.cnf -uroot -p`cat /etc/sqlpass` --idle-time 60 --kill --victims all --interval 10 每隔10s 殺掉已經sleep達到60秒的連線數;
匹配狀態stat處於sendind data的
[root@HaoDai_App_DB01 toolsqldir]# pt-kill --defaults-file=/data/mydata/my_3307.cnf -uroot -p`cat /etc/sqlpass` --match-state Sending --kill --victims all --interval 5
[root@HaoDai_App_DB01 toolsqldir]# pt-kill --defaults-file=/data/mydata/my_3307.cnf -uroot -p`cat /etc/sqlpass` --match-state Sending --kill --victims all --interval 5
-
引數
-
–busy-time
-
執行時間
-
–idle-time
-
空閒時間
-
–victims
-
所有匹配的連線,對應有最久的連線
-
–interval
-
間隔時間,預設30s,有點長,可以根據實際情況來調節
-
–print
-
列印出來kill掉的連線
-
-
–match-command
-
匹配當前連線的命令
-
-
Query
-
Sleep
-
Binlog Dump
-
Connect
-
Delayed insert
-
Execute
-
Fetch
-
Init DB
-
Kill
-
Prepare
-
Processlist
-
Quit
-
Reset stmt
-
Table Dump
-
–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-info
-
使用正規表示式匹配符合的sql
-
–match-db –match-user –match-host
-
見名知意
-
常用用法
-
殺掉空閒連結
-
pt-kill –match-command Sleep –idle-time 5 –host –port –interval –print –kill –victims all
-
殺掉執行時間超過5s的連結
-
pt-kill –match-command Query –busy-time 5 –host –port –interval –print –kill –victims all
-
殺掉匹配某個規則的正在執行的sql
-
pt-kill –match-command Query –busy-time 5 –host –port –interval –print –kill –victims all –match-info
-
殺掉正在進行filesort的sql
-
pt-kill –match-command Query –match-state “Sorting result” busy-time 5 –host –port –interval –print –kill –victims all
-
殺掉正在Copying to tmp table的sql
- pt-kill –match-command Query –match-state “Copying to tmp table” busy-time 5 –host –port –interval –print –kill –victims all
幾個重要引數
--daemonize 放在後臺以守護程式的形式執行; --interval 多久執行一次,單位可以是s,m,h,d等預設是s --victims 預設是oldest,只殺最古老的查詢。這是防止被查殺是不是真的長時間執行的查詢,他們只是長期等待。這種種匹配按時間查詢,殺死一個時間最高值。 all 殺掉所有滿足的執行緒 殺死所有,但最長的保留不殺 action --kill 殺掉連線並且退出 --kill-query 只殺掉連線執行的語句,但是執行緒不會被終止 --print 列印滿足條件的語句
QUERY MATCHES
--busy-time 批次查詢已執行的時間超過這個時間的執行緒; --idle-time 殺掉sleep 了多少時間的連線執行緒,必須在--match-command sleep時才有效
- opition檢視引數吧
- Usage: pt-kill [OPTIONS] [DSN] Options: --ask-pass Prompt for a password when connecting to MySQL --charset=s -A Default character set --config=A Read this comma-separated list of config files; if specified, this must be the first option on the command line --create-log-table Create the --log-dsn table if it does not exist --daemonize Fork to the background and detach from the shell --database=s -D The database to use for the connection --defaults-file=s -F Only read mysql options from the given file --filter=s Discard events for which this Perl code doesn't return true --group-by=s Apply matches to each class of queries grouped by this SHOW PROCESSLIST column --help Show help and exit --host=s -h Connect to host (default localhost) --interval=m How often to check for queries to kill. Optional suffix s=seconds, m=minutes, h=hours, d=days; if no suffix, s is used. --log=s Print all output to this file when daemonized --log-dsn=d Store each query killed in this DSN --password=s -p Password to use when connecting --pid=s Create the given PID file --port=i -P Port number to use for connection --query-id Prints an ID of the query that was just killed --rds Denotes the instance in question is on Amazon RDS --run-time=m How long to run before exiting. Optional suffix s= seconds, m=minutes, h=hours, d=days; if no suffix, s is used. --sentinel=s Exit if this file exists (default /tmp/pt-kill- sentinel) --set-vars=A Set the MySQL variables in this comma-separated list of variable=value pairs --socket=s -S Socket file to use for connection --stop Stop running instances by creating the --sentinel file --[no]strip-comments Remove SQL comments from queries in the Info column of the PROCESSLIST (default yes) --user=s -u User for login if not current user --verbose -v Print information to STDOUT about what is being done --version Show version and exit --[no]version-check Check for the latest version of Percona Toolkit, MySQL, and other programs (default yes) --victims=s Which of the matching queries in each class will be killed (default oldest) --wait-after-kill=m Wait after killing a query, before looking for more to kill. Optional suffix s=seconds, m=minutes, h=hours, d=days; if no suffix, s is used. --wait-before-kill=m Wait before killing a query. Optional suffix s= seconds, m=minutes, h=hours, d=days; if no suffix, s is used. Actions: --execute-command=s Execute this command when a query matches --kill Kill the connection for matching queries --kill-query Kill matching queries --print Print a KILL statement for matching queries; does not actually kill queries Class Matches: --any-busy-time=m Match query class if any query has been running for longer than this time. "Longer than" means that if you specify 10, for example, the class will only match if there's at least one query that has been running for greater than 10 seconds. Optional suffix s=seconds, m= minutes, h=hours, d=days; if no suffix, s is used. --each-busy-time=m Match query class if each query has been running for longer than this time. "Longer than" means that if you specify 10, for example, the class will only match if each and every query has been running for greater than 10 seconds. Optional suffix s=seconds, m=minutes, h= hours, d=days; if no suffix, s is used. --query-count=i Match query class if it has at least this many queries Query Matches: --busy-time=m Match queries that have been running for longer than this time. Optional suffix s=seconds, m=minutes, h= hours, d=days; if no suffix, s is used. --idle-time=m Match queries that have been idle/sleeping for longer than this time. Optional suffix s=seconds, m=minutes, h=hours, d=days; if no suffix, s is used. --ignore-command=s Ignore queries whose Command matches this Perl regex --ignore-db=s Ignore queries whose db (database) matches this Perl regex --ignore-host=s Ignore queries whose Host matches this Perl regex --ignore-info=s Ignore queries whose Info (query) matches this Perl regex --[no]ignore-self Don't kill pt-kill's own connection (default yes) --ignore-state=s Ignore queries whose State matches this Perl regex ( default Locked) --ignore-user=s Ignore queries whose user matches this Perl regex --match-all Match all queries that are not ignored --match-command=s Match only queries whose Command matches this Perl regex --match-db=s Match only queries whose db (database) matches this Perl regex --match-host=s Match only queries whose Host matches this Perl regex --match-info=s Match only queries whose Info (query) matches this Perl regex --match-state=s Match only queries whose State matches this Perl regex --match-user=s Match only queries whose User matches this Perl regex --replication-threads Allow matching and killing replication threads --test-matching=a Files with processlist snapshots to test matching options against
來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/29096438/viewspace-2122904/,如需轉載,請註明出處,否則將追究法律責任。
相關文章
- percona 實用工具之pt-kill使用介紹
- MySQL使用pt-kill殺除大SQLMySql
- Percona-Toolkit 之 pt-kill 用法
- Percona-Toolkit 之 pt-kill 低效SQLSQL
- percona-tools 之 pt-kill 引數詳解
- Percona-Tookit工具包之pt-mysql-summaryMySql
- MySQL online ddl 工具之pt-online-schema-changeMySql
- 【MySQL】online ddl 工具之pt-online-schema-changeMySql
- MySQL pt-duplicate-key-checker工具使用初探MySql
- MySQL效能剖析工具(pt-query-digest)MySql
- mysql運維利器percona-toolkit工具之pt-query-digestMySql運維
- 【pt系列】MySQL慢日誌分析工具pt-query-digest使用、報告分析MySql
- mysql 必須掌握的工具pt-query-digestMySql
- percona-toolkit 之 【pt-summary】、【pt-mysql-summary】、【pt-config-diff】、【pt-variable-advisor】說明MySql
- 使用pt-kill根據一定的規則來kill連線的方法
- Percona-Toolkit工具包之pt-archiverHive
- Percona-Tookit工具包之pt-ioprofile
- Percona-Tookit工具包之pt-mext
- Percona-Tookit工具包之pt-pmp
- MySQL 慢查詢分析工具~pt-query-digest 詳解MySql
- MySQL修改大表工具pt-online-schema-change原理MySql
- 一個 MySQL 線上 DDL 工具 — pt-online-schema-changeMySql
- Percona-Tookit工具包之pt-table-usage
- Percona-Tookit工具包之pt-slave-find
- Percona-Tookit工具包之pt-table-checksum
- pt-archiver工具的使用Hive
- Percona-Tookit工具包之pt-query-digest
- Percona-Tookit工具包之pt-visual-explainAI
- mysql主從恢復資料一致性(pt工具-t-table-checksum和pt-table-sync)MySql
- pt-table-checksum工具應用
- pt-osc(pt-online-schema-change)工具實現原理剖析
- 【工具】MySQL 壓測工具之mydbtestMySql
- MySQL pt-show-grants用法介紹MySql
- MySQL執行狀態監控(pt-mysql-summary)MySql
- 驗證MySQL主從一致性(pt-table-checksum&pt-table-sync)MySql
- pt-archiver實現MySQL定期分表HiveMySql
- 使用pt工具檢測MySQL主從延遲(r12筆記第7天)MySql筆記
- MySQL效能分析工具之PROFILEMySql