Rechercher une page de manuel
mk-kill.1p
Langue: en
Version: 2010-08-01 (fedora - 01/12/10)
Section: 1 (Commandes utilisateur)
Sommaire
NAME
mk-kill - Kill MySQL queries that match certain criteria.SYNOPSIS
Kill queries running longer than 60s:mk-kill --busy-time 60 --kill
Print, do not kill, queries running longer than 60s:
mk-kill --busy-time 60 --print
Check for sleeping processes and kill them all every 10s:
mk-kill --match-command Sleep --kill --no-only-oldest --interval 10
Print all login processes:
mk-kill --match-state login --print --no-only-oldest
RISKS
The following section is included to inform users about the potential risks, whether known or unknown, of using this tool. The two main categories of risks are those created by the nature of the tool (e.g. read-only tools vs. read-write tools) and those created by bugs.mk-kill is designed to kill queries if you use the ``--kill'' option is given, and that might disrupt your database's users, of course. You should test with the <``--print''> option, which is safe, if you're unsure what the tool will do.
At the time of this release, we know of no bugs that could cause serious harm to users.
The authoritative source for updated information is always the online issue tracking system. Issues that affect this tool will be marked as such. You can see a list of such issues at the following URL: http://www.maatkit.org/bugs/mk-kill <http://www.maatkit.org/bugs/mk-kill>.
See also ``BUGS'' for more information on filing bugs and getting help.
DESCRIPTION
mk-kill captures queries from SHOW PROCESSLIST, filters them, and then either kills or prints them. This is also known as a ``slow query sniper'' in some circles. The idea is to watch for queries that might be consuming too many resources, and kill them.For brevity, we talk about killing queries, but they may just be printed (or some other future action) depending on what options are given.
Normally mk-kill connects to MySQL to get queries from SHOW PROCESSLIST. Alternatively, it can read SHOW PROCESSLIST output from files. In this case, mk-kill does not connect to MySQL and ``--kill'' has no effect. You should use ``--print'' instead when reading files. The ability to read a file (or - for STDIN) allows you to capture SHOW PROCESSLIST and test it later with mk-kill to make sure that your matches kill the proper queries. There are a lot of special rules to follow, such as ``don't kill replication threads,'' so be careful to not kill something important!
Two important options to know are ``--busy-time'' and ``--[no]only-oldest''. First, whereas most match/filter options match their corresponding value from SHOW PROCESSLIST (e.g. ``--match-command'' matches a query's Command value), the Time value is matched by ``--busy-time''. See also ``--interval''.
Secondly, ``--[no]only-oldest'' affects which matching query is killed. By default, the matching query with the highest Time value is killed. So if you want to match and kill ALL queries for a certain criteria regardless of which is the ``oldest'', you must specify "--no-only-oldest".
mk-kill is a work in progress, and there is much more it could do.
OUTPUT
If only ``--kill'' then there is no output. If only ``--print'' then a timestamped KILL statement if printed for every query that would have been killed, like:# 2009-07-15T15:04:01 KILL 8 (Query 42 sec) SELECT * FROM huge_table
The line shows a timestamp, the query's Id (8), its Time (42 sec) and its Info (usually the query SQL).
If both ``--kill'' and ``--print'' are given, then matching queries are killed and a line for each like the one above is printed.
Any command executed by ``--execute-command'' is responsible for its own output and logging. After being executed, mk-kill has no control or interaction with the command.
OPTIONS
Specify at least one of ``--kill'', ``--kill-query'', ``--print'' or ``--execute-command''.- --ask-pass
- Prompt for a password when connecting to MySQL.
- --charset
- short form: -A; type: string
Default character set. If the value is utf8, sets Perl's binmode on STDOUT to utf8, passes the mysql_enable_utf8 option to DBD::mysql, and runs SET NAMES UTF8 after connecting to MySQL. Any other value sets binmode on STDOUT without the utf8 layer, and runs SET NAMES after connecting to MySQL.
- --config
- type: Array
Read this comma-separated list of config files; if specified, this must be the first option on the command line.
- --daemonize
- Fork to the background and detach from the shell. POSIX operating systems only.
- --defaults-file
- short form: -F; type: string
Only read mysql options from the given file. You must give an absolute pathname.
- --heartbeat
- Print information to STDOUT about what is being done.
- --help
- Show help and exit.
- --host
- short form: -h; type: string
Connect to host.
- --interval
- type: time
How often to check for queries to kill. If ``--busy-time'' is not given, then the default interval is 30 seconds. Else the default is half as often as ``--busy-time''. If both ``--interval'' and ``--busy-time'' are given, then the explicit ``--interval'' value is used.
- --iterations
- type: int; default: 1
How many times to iterate through the find-and-kill cycle. If 0, iterate to infinity. See also ``--run-time''.
- --log
- type: string
Print all output to this file when daemonized.
- --password
- short form: -p; type: string
Password to use when connecting.
- --pid
- type: string
Create the given PID file when daemonized. The file contains the process ID of the daemonized instance. The PID file is removed when the daemonized instance exits. The program checks for the existence of the PID file when starting; if it exists and the process with the matching PID exists, the program exits.
- --port
- short form: -P; type: int
Port number to use for connection.
- --run-time
- type: time
How long to run before exiting.
- --set-vars
- type: string; default: wait_timeout=10000
Set these MySQL variables. Immediately after connecting to MySQL, this string will be appended to SET and executed.
- --socket
- short form: -S; type: string
Socket file to use for connection.
- --user
- short form: -u; type: string
User for login if not current user.
- --version
- Show version and exit.
- --wait-after-kill
- type: time
Wait after killing a query, before looking for more to kill. The purpose of this is to give blocked queries a chance to execute, so we don't kill a query that's blocking a bunch of others, and then kill the others immediately afterwards.
- --wait-before-kill
- type: time
Wait before killing a query. The purpose of this is to give ``--execute-command'' a chance to see the matching query and gather other MySQL or system information before it's killed.
MATCHES
These options specify what criteria a query must match for "mk-kill" to either ``--kill'', ``--print'' or ``--execute-command'' for it. The ignore commands take precedence. The matches for command, db, host, etc. correspond to the columns returned by SHOW PROCESSLIST: Command, db, Host, etc. All pattern matches are case-senstive.- --all
- group: Matches
Kill all connections that are not ignored.
If no ignore options are specified, then every connection is killed (except replication threads, unless ``--replication-threads'' is also specified). If some ignore options are specified, then every connection except ignored connections are killed.
Implies "--no-only-oldest".
- --busy-time
- type: time; group: Matches
Kill connections that have been running for longer than this time. The queries must be in Command=Query status. This matches a query's Time value as reported by SHOW PROCESSLIST.
- --idle-time
- type: time; group: Matches
Kill connections that have been idle/sleeping for longer than this time. The queries must be in Command=Sleep status. This matches a query's Time value as reported by SHOW PROCESSLIST.
- --ignore-command
- type: string; group: Matches
Ignore queries whose Command matches this Perl regex.
See ``--match-command''.
- --ignore-db
- type: string; group: Matches
Ignore queries whose db (database) matches this Perl regex.
See ``--match-db''.
- --ignore-host
- type: string; group: Matches
Ignore queries whose Host matches this Perl regex.
See ``--match-host''.
- --ignore-info
- type: string; group: Matches
Ignore queries whose Info (query) matches this Perl regex.
See ``--match-info''.
- --[no]ignore-self
- default: yes; group: Matches
Don't kill mk-kill's own connection.
- --ignore-state
- type: string; group: Matches; default: Locked
Ignore queries whose State matches this Perl regex. The default is to keep threads from being killed if they are locked waiting for another thread.
See ``--match-state''.
- --ignore-user
- type: string; group: Matches
Ignore queries whose user matches this Perl regex.
See ``--match-user''.
- --match-command
- type: string; group: Matches
Kill 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 <http://dev.mysql.com/doc/refman/5.1/en/thread-commands.html> for a full list and description of Command values.
- --match-db
- type: string; group: Matches
Kill only queries whose db (database) matches this Perl regex.
- --match-host
- type: string; group: Matches
Kill only queries whose Host matches this Perl regex.
The Host value often time includes the port like ``host:port''.
- --match-info
- type: string; group: Matches
Kill only queries whose Info (query) matches this Perl regex.
The Info column of the processlist shows the query that is being executed or NULL if no query is being executed.
- --match-state
- type: string; group: Matches
Kill 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 <http://dev.mysql.com/doc/refman/5.1/en/general-thread-states.html> for a full list and description of State values.
- --match-user
- type: string; group: Matches
Kill only queries whose User matches this Perl regex.
- --[no]only-oldest
- default: yes; group: Matches
Only kill the single oldest query. This is to prevent killing queries that aren't really long-running, they're just long-waiting. This sorts matching queries by Time and kills the one with the highest Time value.
This option is disabled if ``--all'' is specified.
- --replication-threads
- group: Matches
Allow matching and killing replication threads.
By default, matches do not apply to replication threads; i.e. replication threads are completely ignored. Specifying this option allows matches to match (and potentially kill) replication threads on masters and slaves.
ACTIONS
When a query matches, one or more of these actions is taken. The actions are taken in this order: ``--print'', ``--execute-command'', ``--kill''. If given, mk-kill sleeps for ``--wait-before-kill'' before ``--kill'' (if ``--kill'' is given). This order allows ``--execute-command'' to see the output of ``--print'' and the query before ``--kill''. This may be helpful because mk-kill does not pass any information to ``--execute-command''.- --execute-command
- type: string; group: Actions
Execute this command when a query matches.
After the command is executed, mk-kill has no control over it, so the command is responsible for its own info gathering, logging, interval, etc. The command is excuted each time a query matches, so be careful that the command behaves well when multiple instances are ran. No information from mk-kill is passed to the command.
See also ``--wait-before-kill''.
- --kill
- group: Actions
Kill the connection for matching queries.
This option makes mk-kill kill the connections (a.k.a. processes, threads) that have matching queries. Use ``--kill-query'' if you only want to kill individual queries and not their connections. If both ``--kill'' and ``--kill-query'' are specified, only ``--kill-query'' is used.
Unless ``--print'' is also given, no other information is printed that shows that mk-kill matched and killed a query.
See also ``--wait-before-kill'' and ``--wait-after-kill''.
- --kill-query
- group: Actions
Kill matching queries.
This option makes mk-kill kill matching queries. This requires MySQL 5.0 or newer. Unlike ``--kill'' which kills the connection for matching queries, this option only kills the query, not its connection. If both ``--kill'' and ``--kill-query'' are specified, only ``--kill-query'' is used.
- group: Actions
Print a KILL statement for matching queries; does not actually kill queries.
If you just want to see which queries match and would be killed without actually killing them, specify ``--print''. To both kill and print matching queries, specify both ``--kill'' and ``--print''.
DSN OPTIONS
These DSN options are used to create a DSN. Each option is given like "option=value". The options are case-sensitive, so P and p are not the same option. There cannot be whitespace before or after the "=" and if the value contains whitespace it must be quoted. DSN options are comma-separated. See the maatkit manpage for full details.- *
- A
dsn: charset; copy: yes
Default character set.
- *
- D
dsn: database; copy: yes
Default database.
- *
- F
dsn: mysql_read_default_file; copy: yes
Only read default options from the given file
- *
- h
dsn: host; copy: yes
Connect to host.
- *
- p
dsn: password; copy: yes
Password to use when connecting.
- *
- P
dsn: port; copy: yes
Port number to use for connection.
- *
- S
dsn: mysql_socket; copy: yes
Socket file to use for connection.
- *
- u
dsn: user; copy: yes
User for login if not current user.
DOWNLOADING
You can download Maatkit from Google Code at <http://code.google.com/p/maatkit/>, or you can get any of the tools easily with a command like the following:wget http://www.maatkit.org/get/toolname or wget http://www.maatkit.org/trunk/toolname
Where "toolname" can be replaced with the name (or fragment of a name) of any of the Maatkit tools. Once downloaded, they're ready to run; no installation is needed. The first URL gets the latest released version of the tool, and the second gets the latest trunk code from Subversion.
ENVIRONMENT
The environment variable "MKDEBUG" enables verbose debugging output in all of the Maatkit tools:MKDEBUG=1 mk-....
SYSTEM REQUIREMENTS
You need Perl, DBI, DBD::mysql, and some core packages that ought to be installed in any reasonably new version of Perl.BUGS
For list of known bugs see http://www.maatkit.org/bugs/mk-kill <http://www.maatkit.org/bugs/mk-kill>.Please use Google Code Issues and Groups to report bugs or request support: <http://code.google.com/p/maatkit/>. You can also join #maatkit on Freenode to discuss Maatkit.
Please include the complete command-line used to reproduce the problem you are seeing, the version of all MySQL servers involved, the complete output of the tool when run with ``--version'', and if possible, debugging output produced by running with the "MKDEBUG=1" environment variable.
COPYRIGHT, LICENSE AND WARRANTY
This program is copyright 2009-2010 Baron Schwartz. Feedback and improvements are welcome.THIS PROGRAM IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, version 2; OR the Perl Artistic License. On UNIX and similar systems, you can issue `man perlgpl' or `man perlartistic' to read these licenses.
You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
AUTHOR
Baron SchwartzABOUT MAATKIT
This tool is part of Maatkit, a toolkit for power users of MySQL. Maatkit was created by Baron Schwartz; Baron and Daniel Nichter are the primary code contributors. Both are employed by Percona. Financial support for Maatkit development is primarily provided by Percona and its clients.VERSION
This manual page documents Ver 0.9.6 Distrib 6839 $Revision: 6831 $.Contenus ©2006-2024 Benjamin Poulain
Design ©2006-2024 Maxime Vantorre