percona 實用工具之pt-kill

pt-kill

概述

從show processlist 中獲取滿足條件的連接或者從包含show processlist的文件中讀取滿足條件的連接並打印或者殺掉或者執行其他操作,這個工具在工作中實用性很高,當服務器連接出現異常後第一想到的就是pt-kill,自己寫一個腳本也可以,但是功能還是沒有pt-kill強大;一般我喜歡將連接本地mysql的必要信息放在一個文件文件中,當需要連接本地mysql時直接指定配置文件即可;


常用功能介紹

pt-kill --defaults-file xx --match-command Sleep --kill --victims all --interval 10 每隔10s 殺掉處於sleep狀態的連接數;

pt-kill defaults-file xx --busy-time 60 --kill --victims all --interval 10 每隔10s 殺掉處初步runnning狀態超過60s的連接數;


幾個重要參數
--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時纔有效
--ignore-command

type: string; group: Query Matches

Ignore queries whose Command matches this Perl regex.

See --match-command.

--ignore-db

type: string; group: Query Matches

Ignore queries whose db (database) matches this Perl regex.

See --match-db.

--ignore-host

type: string; group: Query Matches

Ignore queries whose Host matches this Perl regex.

See --match-host.

--ignore-info

type: string; group: Query Matches

Ignore queries whose Info (query) matches this Perl regex.

See --match-info.

--[no]ignore-self

default: yes; group: Query Matches

Don’t kill pt-kill‘s own connection.

--ignore-state

type: string; group: Query Matches; default: Locked

Ignore queries whose State matches this Perl regex. The default is to keepthreads from being killed if they are locked waiting for another thread.

See --match-state.

--ignore-user

type: string; group: Query Matches

Ignore queries whose user matches this Perl regex.

See --match-user.

--match-all

group: Query Matches

Match all queries that are not ignored. If no ignore options are specified,then every query matches (except replication threads, unless--replication-threads is also specified). This option allows you tospecify negative matches, i.e. “match every query except...” where theexceptions are defined by specifying various --ignore options.

This option is not the same as --victims all. This option matchesall queries within a class, whereas --victims all specifies that allmatching queries in a class (however they matched) will be killed. Normally,however, the two are used together because if, for example, you specify--victims oldest, then although all queries may match, only the oldestwill be killed.

--match-command

type: string; group: Query Matches

Match only queries whose Command matches this Perl regex.

Common Command values are:

Query
Sleep
Binlog Dump
Connect
Delayed insert
Execute
Fetch
Init DB
Kill
Prepare
Processlist
Quit
Reset stmt
Table Dump

See http://dev.mysql.com/doc/refman/5.1/en/thread-commands.html for a fulllist and description of Command values.

--match-db

type: string; group: Query Matches

Match only queries whose db (database) matches this Perl regex.

--match-host

type: string; group: Query Matches

Match only queries whose Host matches this Perl regex.

The Host value often time includes the port like “host:port”.

--match-info

type: string; group: Query Matches

Match only queries whose Info (query) matches this Perl regex.

The Info column of the processlist shows the query that is being executedor NULL if no query is being executed.

--match-state

type: string; group: Query Matches

Match only queries whose State matches this Perl regex.

Common State values are:

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

See http://dev.mysql.com/doc/refman/5.1/en/general-thread-states.html fora full list and description of State values.

--match-user

type: string; group: Query Matches

Match only queries whose User matches this Perl regex.

--replication-threads

group: Query Matches

Allow matching and killing replication threads.

By default, matches do not apply to replication threads; i.e. replicationthreads are completely ignored. Specifying this option allows matches tomatch (and potentially kill) replication threads on masters and slaves.

--test-matching

type: array; group: Query Matches

Files with processlist snapshots to test matching options against. Sincethe matching options can be complex, you can save snapshots of processlistin files, then test matching options against queries in those files.

This option disables --run-time, --interval,and --[no]ignore-self.





發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章