14
pt-slave-restart - Watch and restart MySQL replication after errors.
22
Usage: pt-slave-restart [OPTION...] [DSN]
24
pt-slave-restart watches one or more MySQL replication slaves for
25
errors, and tries to restart replication if it stops.
33
The following section is included to inform users about the potential risks,
34
whether known or unknown, of using this tool. The two main categories of risks
35
are those created by the nature of the tool (e.g. read-only tools vs. read-write
36
tools) and those created by bugs.
38
pt-slave-restart is a brute-force way to try to keep a slave server running when
39
it is having problems with replication. Don't be too hasty to use it unless you
40
need to. If you use this tool carelessly, you might miss the chance to really
41
solve the slave server's problems.
43
At the time of this release there is a bug that causes an invalid
44
\ ``CHANGE MASTER TO``\ statement to be executed.
46
The authoritative source for updated information is always the online issue
47
tracking system. Issues that affect this tool will be marked as such. You can
48
see a list of such issues at the following URL:
49
`http://www.percona.com/bugs/pt-slave-restart <http://www.percona.com/bugs/pt-slave-restart>`_.
51
See also "BUGS" for more information on filing bugs and getting help.
59
pt-slave-restart watches one or more MySQL replication slaves and tries to skip
60
statements that cause errors. It polls slaves intelligently with an
61
exponentially varying sleep time. You can specify errors to skip and run the
62
slaves until a certain binlog position.
64
Note: it has come to my attention that Yahoo! had or has an internal tool
65
called fix_repl, described to me by a past Yahoo! employee and mentioned in
66
the first edition of High Performance MySQL. Apparently this tool does the
67
same thing. Make no mistake, though: this is not a way to "fix replication."
68
In fact I would not even encourage its use on a regular basis; I use it only
69
when I have an error I know I just need to skip past.
77
If you specify "--verbose", pt-slave-restart prints a line every time it sees
78
the slave has an error. See "--verbose" for details.
86
pt-slave-restart sleeps intelligently between polling the slave. The current
92
The initial sleep time is given by "--sleep".
98
If it checks and finds an error, it halves the previous sleep time.
104
If it finds no error, it doubles the previous sleep time.
110
The sleep time is bounded below by "--min-sleep" and above by
117
Immediately after finding an error, pt-slave-restart assumes another error is
118
very likely to happen next, so it sleeps the current sleep time or the initial
119
sleep time, whichever is less.
129
An exit status of 0 (sometimes also called a return value or return code)
130
indicates success. Any other value represents the exit status of the Perl
131
process itself, or of the last forked process that exited if there were multiple
140
pt-slave-restart should work on many versions of MySQL. Lettercase of many
141
output columns from SHOW SLAVE STATUS has changed over time, so it treats them
150
This tool accepts additional command-line arguments. Refer to the
151
"SYNOPSIS" and usage information for details.
156
Start slaves even when there is no error. With this option enabled,
157
pt-slave-restart will not let you stop the slave manually if you want to!
163
Prompt for a password when connecting to MySQL.
169
short form: -A; type: string
171
Default character set. If the value is utf8, sets Perl's binmode on
172
STDOUT to utf8, passes the mysql_enable_utf8 option to DBD::mysql, and
173
runs SET NAMES UTF8 after connecting to MySQL. Any other value sets
174
binmode on STDOUT without the utf8 layer, and runs SET NAMES after
179
--[no]check-relay-log
183
Check the last relay log file and position before checking for slave errors.
185
By default pt-slave-restart will not doing anything (it will just sleep)
186
if neither the relay log file nor the relay log position have changed since
187
the last check. This prevents infinite loops (i.e. restarting the same
188
error in the same relay log file at the same relay log position).
190
For certain slave errors, however, this check needs to be disabled by
191
specifying \ ``--no-check-relay-log``\ . Do not do this unless you know what
200
Read this comma-separated list of config files; if specified, this must be the
201
first option on the command line.
207
Fork to the background and detach from the shell. POSIX
208
operating systems only.
214
short form: -D; type: string
222
short form: -F; type: string
224
Only read mysql options from the given file. You must give an absolute
233
Max length of error message to print. When "--verbose" is set high enough to
234
print the error, this option will truncate the error text to the specified
235
length. This can be useful to prevent wrapping on the terminal.
243
Only restart this comma-separated list of errors. Makes pt-slave-restart only
244
try to restart if the error number is in this comma-separated list of errors.
245
If it sees an error not in the list, it will exit.
247
The error number is in the \ ``last_errno``\ column of \ ``SHOW SLAVE STATUS``\ .
255
Only restart errors that match this pattern. A Perl regular expression against
256
which the error text, if any, is matched. If the error text exists and matches,
257
pt-slave-restart will try to restart the slave. If it exists but doesn't match,
258
pt-slave-restart will exit.
260
The error text is in the \ ``last_error``\ column of \ ``SHOW SLAVE STATUS``\ .
272
short form: -h; type: string
282
Print all output to this file when daemonized.
288
type: float; default: 64
290
Maximum sleep seconds.
292
The maximum time pt-slave-restart will sleep before polling the slave again.
293
This is also the time that pt-slave-restart will wait for all other running
294
instances to quit if both "--stop" and "--monitor" are specified.
302
type: float; default: 0.015625
304
The minimum time pt-slave-restart will sleep before polling the slave again.
311
Whether to monitor the slave (default). Unless you specify --monitor
312
explicitly, "--stop" will disable it.
318
short form: -p; type: string
320
Password to use when connecting.
328
Create the given PID file when daemonized. The file contains the process
329
ID of the daemonized instance. The PID file is removed when the
330
daemonized instance exits. The program checks for the existence of the
331
PID file when starting; if it exists and the process with the matching PID
332
exists, the program exits.
338
short form: -P; type: int
340
Port number to use for connection.
348
Suppresses normal output (disables "--verbose").
354
type: int; default: 0
356
Watch slaves of the specified server, up to the specified number of servers deep
357
in the hierarchy. The default depth of 0 means "just watch the slave
360
pt-slave-restart examines \ ``SHOW PROCESSLIST``\ and tries to determine which
361
connections are from slaves, then connect to them. See "--recursion-method".
363
Recursion works by finding all slaves when the program starts, then watching
364
them. If there is more than one slave, \ ``pt-slave-restart``\ uses \ ``fork()``\ to
367
This also works if you have configured your slaves to show up in \ ``SHOW SLAVE
368
HOSTS``\ . The minimal configuration for this is the \ ``report_host``\ parameter, but
369
there are other "report" parameters as well for the port, username, and
378
Preferred recursion method used to find slaves.
380
Possible methods are:
386
=========== ================
387
processlist SHOW PROCESSLIST
388
hosts SHOW SLAVE HOSTS
391
The processlist method is preferred because SHOW SLAVE HOSTS is not reliable.
392
However, the hosts method is required if the server uses a non-standard
393
port (not 3306). Usually pt-slave-restart does the right thing and finds
394
the slaves, but you may give a preferred method and it will be used first.
395
If it doesn't find any slaves, the other methods will be tried.
403
Time to run before exiting. Causes pt-slave-restart to stop after the specified
404
time has elapsed. Optional suffix: s=seconds, m=minutes, h=hours, d=days; if no
411
type: string; default: /tmp/pt-slave-restart-sentinel
413
Exit if this file exists.
419
type: string; default: wait_timeout=10000
421
Set these MySQL variables. Immediately after connecting to MySQL, this string
422
will be appended to SET and executed.
428
type: int; default: 1
430
Number of statements to skip when restarting the slave.
436
type: int; default: 1
438
Initial sleep seconds between checking the slave.
446
short form: -S; type: string
448
Socket file to use for connection.
454
Stop running instances by creating the sentinel file.
456
Causes \ ``pt-slave-restart``\ to create the sentinel file specified by
457
"--sentinel". This should have the effect of stopping all running
458
instances which are watching the same sentinel file. If "--monitor" isn't
459
specified, \ ``pt-slave-restart``\ will exit after creating the file. If it is
460
specified, \ ``pt-slave-restart``\ will wait the interval given by
461
"--max-sleep", then remove the file and continue working.
463
You might find this handy to stop cron jobs gracefully if necessary, or to
464
replace one running instance with another. For example, if you want to stop
465
and restart \ ``pt-slave-restart``\ every hour (just to make sure that it is
466
restarted every hour, in case of a server crash or some other problem), you
467
could use a \ ``crontab``\ line like this:
472
0 * * * * pt-slave-restart --monitor --stop --sentinel /tmp/pt-slave-restartup
475
The non-default "--sentinel" will make sure the hourly \ ``cron``\ job stops
476
only instances previously started with the same options (that is, from the
477
same \ ``cron``\ job).
479
See also "--sentinel".
487
Run until this master log file and position. Start the slave, and retry if it
488
fails, until it reaches the given replication coordinates. The coordinates are
489
the logfile and position on the master, given by relay_master_log_file,
490
exec_master_log_pos. The argument must be in the format "file,pos". Separate
491
the filename and position with a single comma and no space.
493
This will also cause an UNTIL clause to be given to START SLAVE.
495
After reaching this point, the slave should be stopped and pt-slave-restart
504
Run until this relay log file and position. Like "--until-master", but in
505
the slave's relay logs instead. The coordinates are given by relay_log_file,
512
short form: -u; type: string
514
User for login if not current user.
520
short form: -v; cumulative: yes; default: 1
522
Be verbose; can specify multiple times. Verbosity 1 outputs connection
523
information, a timestamp, relay_log_file, relay_log_pos, and last_errno.
524
Verbosity 2 adds last_error. See also "--error-length". Verbosity 3 prints
525
the current sleep time each time pt-slave-restart sleeps.
533
Show version and exit.
541
These DSN options are used to create a DSN. Each option is given like
542
\ ``option=value``\ . The options are case-sensitive, so P and p are not the
543
same option. There cannot be whitespace before or after the \ ``=``\ and
544
if the value contains whitespace it must be quoted. DSN options are
545
comma-separated. See the percona-toolkit manpage for full details.
550
dsn: charset; copy: yes
552
Default character set.
558
dsn: database; copy: yes
566
dsn: mysql_read_default_file; copy: yes
568
Only read default options from the given file
582
dsn: password; copy: yes
584
Password to use when connecting.
592
Port number to use for connection.
598
dsn: mysql_socket; copy: yes
600
Socket file to use for connection.
608
User for login if not current user.
618
The environment variable \ ``PTDEBUG``\ enables verbose debugging output to STDERR.
619
To enable debugging and capture all output to a file, run the tool like:
624
PTDEBUG=1 pt-slave-restart ... > FILE 2>&1
627
Be careful: debugging output is voluminous and can generate several megabytes
636
You need Perl, DBI, DBD::mysql, and some core packages that ought to be
637
installed in any reasonably new version of Perl.
645
For a list of known bugs, see `http://www.percona.com/bugs/pt-slave-restart <http://www.percona.com/bugs/pt-slave-restart>`_.
647
Please report bugs at `https://bugs.launchpad.net/percona-toolkit <https://bugs.launchpad.net/percona-toolkit>`_.
648
Include the following information in your bug report:
651
\* Complete command-line used to run the tool
659
\* MySQL version of all servers involved
663
\* Output from the tool including STDERR
667
\* Input files (log/dump/config files, etc.)
671
If possible, include debugging output by running the tool with \ ``PTDEBUG``\ ;
680
Visit `http://www.percona.com/software/percona-toolkit/ <http://www.percona.com/software/percona-toolkit/>`_ to download the
681
latest release of Percona Toolkit. Or, get the latest release from the
687
wget percona.com/get/percona-toolkit.tar.gz
689
wget percona.com/get/percona-toolkit.rpm
691
wget percona.com/get/percona-toolkit.deb
694
You can also get individual tools from the latest release:
699
wget percona.com/get/TOOL
702
Replace \ ``TOOL``\ with the name of any tool.
713
*********************
714
ABOUT PERCONA TOOLKIT
715
*********************
718
This tool is part of Percona Toolkit, a collection of advanced command-line
719
tools developed by Percona for MySQL support and consulting. Percona Toolkit
720
was forked from two projects in June, 2011: Maatkit and Aspersa. Those
721
projects were created by Baron Schwartz and developed primarily by him and
722
Daniel Nichter, both of whom are employed by Percona. Visit
723
`http://www.percona.com/software/ <http://www.percona.com/software/>`_ for more software developed by Percona.
726
********************************
727
COPYRIGHT, LICENSE, AND WARRANTY
728
********************************
731
This program is copyright 2007-2011 Baron Schwartz, 2011 Percona Inc.
732
Feedback and improvements are welcome.
734
THIS PROGRAM IS PROVIDED "AS IS" AND WITHOUT ANY EXPRESS OR IMPLIED
735
WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF
736
MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
738
This program is free software; you can redistribute it and/or modify it under
739
the terms of the GNU General Public License as published by the Free Software
740
Foundation, version 2; OR the Perl Artistic License. On UNIX and similar
741
systems, you can issue \`man perlgpl' or \`man perlartistic' to read these
744
You should have received a copy of the GNU General Public License along with
745
this program; if not, write to the Free Software Foundation, Inc., 59 Temple
746
Place, Suite 330, Boston, MA 02111-1307 USA.
754
pt-slave-restart 1.0.2