~percona-toolkit-dev/percona-toolkit/1.0

« back to all changes in this revision

Viewing changes to docs/user/pt-slave-restart.rst

  • Committer: Daniel Nichter
  • Date: 2011-12-29 22:16:13 UTC
  • Revision ID: daniel@percona.com-20111229221613-oprw0q2td34r6zkb
Update release date.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
 
2
 
################
3
 
pt-slave-restart
4
 
################
5
 
 
6
 
.. highlight:: perl
7
 
 
8
 
 
9
 
****
10
 
NAME
11
 
****
12
 
 
13
 
 
14
 
pt-slave-restart - Watch and restart MySQL replication after errors.
15
 
 
16
 
 
17
 
********
18
 
SYNOPSIS
19
 
********
20
 
 
21
 
 
22
 
Usage: pt-slave-restart [OPTION...] [DSN]
23
 
 
24
 
pt-slave-restart watches one or more MySQL replication slaves for
25
 
errors, and tries to restart replication if it stops.
26
 
 
27
 
 
28
 
*****
29
 
RISKS
30
 
*****
31
 
 
32
 
 
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.
37
 
 
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.
42
 
 
43
 
At the time of this release there is a bug that causes an invalid
44
 
\ ``CHANGE MASTER TO``\  statement to be executed.
45
 
 
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>`_.
50
 
 
51
 
See also "BUGS" for more information on filing bugs and getting help.
52
 
 
53
 
 
54
 
***********
55
 
DESCRIPTION
56
 
***********
57
 
 
58
 
 
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.
63
 
 
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.
70
 
 
71
 
 
72
 
******
73
 
OUTPUT
74
 
******
75
 
 
76
 
 
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.
79
 
 
80
 
 
81
 
*****
82
 
SLEEP
83
 
*****
84
 
 
85
 
 
86
 
pt-slave-restart sleeps intelligently between polling the slave.  The current
87
 
sleep time varies.
88
 
 
89
 
 
90
 
\*
91
 
 
92
 
 The initial sleep time is given by "--sleep".
93
 
 
94
 
 
95
 
 
96
 
\*
97
 
 
98
 
 If it checks and finds an error, it halves the previous sleep time.
99
 
 
100
 
 
101
 
 
102
 
\*
103
 
 
104
 
 If it finds no error, it doubles the previous sleep time.
105
 
 
106
 
 
107
 
 
108
 
\*
109
 
 
110
 
 The sleep time is bounded below by "--min-sleep" and above by
111
 
 "--max-sleep".
112
 
 
113
 
 
114
 
 
115
 
\*
116
 
 
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.
120
 
 
121
 
 
122
 
 
123
 
 
124
 
***********
125
 
EXIT STATUS
126
 
***********
127
 
 
128
 
 
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
132
 
servers to monitor.
133
 
 
134
 
 
135
 
*************
136
 
COMPATIBILITY
137
 
*************
138
 
 
139
 
 
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
142
 
all as lowercase.
143
 
 
144
 
 
145
 
*******
146
 
OPTIONS
147
 
*******
148
 
 
149
 
 
150
 
This tool accepts additional command-line arguments.  Refer to the
151
 
"SYNOPSIS" and usage information for details.
152
 
 
153
 
 
154
 
--always
155
 
 
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!
158
 
 
159
 
 
160
 
 
161
 
--ask-pass
162
 
 
163
 
 Prompt for a password when connecting to MySQL.
164
 
 
165
 
 
166
 
 
167
 
--charset
168
 
 
169
 
 short form: -A; type: string
170
 
 
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
175
 
 connecting to MySQL.
176
 
 
177
 
 
178
 
 
179
 
--[no]check-relay-log
180
 
 
181
 
 default: yes
182
 
 
183
 
 Check the last relay log file and position before checking for slave errors.
184
 
 
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).
189
 
 
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
192
 
 you are doing!
193
 
 
194
 
 
195
 
 
196
 
--config
197
 
 
198
 
 type: Array
199
 
 
200
 
 Read this comma-separated list of config files; if specified, this must be the
201
 
 first option on the command line.
202
 
 
203
 
 
204
 
 
205
 
--daemonize
206
 
 
207
 
 Fork to the background and detach from the shell.  POSIX
208
 
 operating systems only.
209
 
 
210
 
 
211
 
 
212
 
--database
213
 
 
214
 
 short form: -D; type: string
215
 
 
216
 
 Database to use.
217
 
 
218
 
 
219
 
 
220
 
--defaults-file
221
 
 
222
 
 short form: -F; type: string
223
 
 
224
 
 Only read mysql options from the given file.  You must give an absolute
225
 
 pathname.
226
 
 
227
 
 
228
 
 
229
 
--error-length
230
 
 
231
 
 type: int
232
 
 
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.
236
 
 
237
 
 
238
 
 
239
 
--error-numbers
240
 
 
241
 
 type: hash
242
 
 
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.
246
 
 
247
 
 The error number is in the \ ``last_errno``\  column of \ ``SHOW SLAVE STATUS``\ .
248
 
 
249
 
 
250
 
 
251
 
--error-text
252
 
 
253
 
 type: string
254
 
 
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.
259
 
 
260
 
 The error text is in the \ ``last_error``\  column of \ ``SHOW SLAVE STATUS``\ .
261
 
 
262
 
 
263
 
 
264
 
--help
265
 
 
266
 
 Show help and exit.
267
 
 
268
 
 
269
 
 
270
 
--host
271
 
 
272
 
 short form: -h; type: string
273
 
 
274
 
 Connect to host.
275
 
 
276
 
 
277
 
 
278
 
--log
279
 
 
280
 
 type: string
281
 
 
282
 
 Print all output to this file when daemonized.
283
 
 
284
 
 
285
 
 
286
 
--max-sleep
287
 
 
288
 
 type: float; default: 64
289
 
 
290
 
 Maximum sleep seconds.
291
 
 
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.
295
 
 
296
 
 See "SLEEP".
297
 
 
298
 
 
299
 
 
300
 
--min-sleep
301
 
 
302
 
 type: float; default: 0.015625
303
 
 
304
 
 The minimum time pt-slave-restart will sleep before polling the slave again.
305
 
 See "SLEEP".
306
 
 
307
 
 
308
 
 
309
 
--monitor
310
 
 
311
 
 Whether to monitor the slave (default).  Unless you specify --monitor
312
 
 explicitly, "--stop" will disable it.
313
 
 
314
 
 
315
 
 
316
 
--password
317
 
 
318
 
 short form: -p; type: string
319
 
 
320
 
 Password to use when connecting.
321
 
 
322
 
 
323
 
 
324
 
--pid
325
 
 
326
 
 type: string
327
 
 
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.
333
 
 
334
 
 
335
 
 
336
 
--port
337
 
 
338
 
 short form: -P; type: int
339
 
 
340
 
 Port number to use for connection.
341
 
 
342
 
 
343
 
 
344
 
--quiet
345
 
 
346
 
 short form: -q
347
 
 
348
 
 Suppresses normal output (disables "--verbose").
349
 
 
350
 
 
351
 
 
352
 
--recurse
353
 
 
354
 
 type: int; default: 0
355
 
 
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
358
 
 specified."
359
 
 
360
 
 pt-slave-restart examines \ ``SHOW PROCESSLIST``\  and tries to determine which
361
 
 connections are from slaves, then connect to them.  See "--recursion-method".
362
 
 
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
365
 
 monitor them.
366
 
 
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
370
 
 password.
371
 
 
372
 
 
373
 
 
374
 
--recursion-method
375
 
 
376
 
 type: string
377
 
 
378
 
 Preferred recursion method used to find slaves.
379
 
 
380
 
 Possible methods are:
381
 
 
382
 
 
383
 
 .. code-block:: perl
384
 
 
385
 
    METHOD       USES
386
 
    ===========  ================
387
 
    processlist  SHOW PROCESSLIST
388
 
    hosts        SHOW SLAVE HOSTS
389
 
 
390
 
 
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.
396
 
 
397
 
 
398
 
 
399
 
--run-time
400
 
 
401
 
 type: time
402
 
 
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
405
 
 suffix, s is used.
406
 
 
407
 
 
408
 
 
409
 
--sentinel
410
 
 
411
 
 type: string; default: /tmp/pt-slave-restart-sentinel
412
 
 
413
 
 Exit if this file exists.
414
 
 
415
 
 
416
 
 
417
 
--set-vars
418
 
 
419
 
 type: string; default: wait_timeout=10000
420
 
 
421
 
 Set these MySQL variables.  Immediately after connecting to MySQL, this string
422
 
 will be appended to SET and executed.
423
 
 
424
 
 
425
 
 
426
 
--skip-count
427
 
 
428
 
 type: int; default: 1
429
 
 
430
 
 Number of statements to skip when restarting the slave.
431
 
 
432
 
 
433
 
 
434
 
--sleep
435
 
 
436
 
 type: int; default: 1
437
 
 
438
 
 Initial sleep seconds between checking the slave.
439
 
 
440
 
 See "SLEEP".
441
 
 
442
 
 
443
 
 
444
 
--socket
445
 
 
446
 
 short form: -S; type: string
447
 
 
448
 
 Socket file to use for connection.
449
 
 
450
 
 
451
 
 
452
 
--stop
453
 
 
454
 
 Stop running instances by creating the sentinel file.
455
 
 
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.
462
 
 
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:
468
 
 
469
 
 
470
 
 .. code-block:: perl
471
 
 
472
 
   0 * * * * pt-slave-restart --monitor --stop --sentinel /tmp/pt-slave-restartup
473
 
 
474
 
 
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).
478
 
 
479
 
 See also "--sentinel".
480
 
 
481
 
 
482
 
 
483
 
--until-master
484
 
 
485
 
 type: string
486
 
 
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.
492
 
 
493
 
 This will also cause an UNTIL clause to be given to START SLAVE.
494
 
 
495
 
 After reaching this point, the slave should be stopped and pt-slave-restart
496
 
 will exit.
497
 
 
498
 
 
499
 
 
500
 
--until-relay
501
 
 
502
 
 type: string
503
 
 
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,
506
 
 relay_log_pos.
507
 
 
508
 
 
509
 
 
510
 
--user
511
 
 
512
 
 short form: -u; type: string
513
 
 
514
 
 User for login if not current user.
515
 
 
516
 
 
517
 
 
518
 
--verbose
519
 
 
520
 
 short form: -v; cumulative: yes; default: 1
521
 
 
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.
526
 
 
527
 
 
528
 
 
529
 
--version
530
 
 
531
 
 
532
 
 
533
 
Show version and exit.
534
 
 
535
 
 
536
 
***********
537
 
DSN OPTIONS
538
 
***********
539
 
 
540
 
 
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.
546
 
 
547
 
 
548
 
\* A
549
 
 
550
 
 dsn: charset; copy: yes
551
 
 
552
 
 Default character set.
553
 
 
554
 
 
555
 
 
556
 
\* D
557
 
 
558
 
 dsn: database; copy: yes
559
 
 
560
 
 Default database.
561
 
 
562
 
 
563
 
 
564
 
\* F
565
 
 
566
 
 dsn: mysql_read_default_file; copy: yes
567
 
 
568
 
 Only read default options from the given file
569
 
 
570
 
 
571
 
 
572
 
\* h
573
 
 
574
 
 dsn: host; copy: yes
575
 
 
576
 
 Connect to host.
577
 
 
578
 
 
579
 
 
580
 
\* p
581
 
 
582
 
 dsn: password; copy: yes
583
 
 
584
 
 Password to use when connecting.
585
 
 
586
 
 
587
 
 
588
 
\* P
589
 
 
590
 
 dsn: port; copy: yes
591
 
 
592
 
 Port number to use for connection.
593
 
 
594
 
 
595
 
 
596
 
\* S
597
 
 
598
 
 dsn: mysql_socket; copy: yes
599
 
 
600
 
 Socket file to use for connection.
601
 
 
602
 
 
603
 
 
604
 
\* u
605
 
 
606
 
 dsn: user; copy: yes
607
 
 
608
 
 User for login if not current user.
609
 
 
610
 
 
611
 
 
612
 
 
613
 
***********
614
 
ENVIRONMENT
615
 
***********
616
 
 
617
 
 
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:
620
 
 
621
 
 
622
 
.. code-block:: perl
623
 
 
624
 
    PTDEBUG=1 pt-slave-restart ... > FILE 2>&1
625
 
 
626
 
 
627
 
Be careful: debugging output is voluminous and can generate several megabytes
628
 
of output.
629
 
 
630
 
 
631
 
*******************
632
 
SYSTEM REQUIREMENTS
633
 
*******************
634
 
 
635
 
 
636
 
You need Perl, DBI, DBD::mysql, and some core packages that ought to be
637
 
installed in any reasonably new version of Perl.
638
 
 
639
 
 
640
 
****
641
 
BUGS
642
 
****
643
 
 
644
 
 
645
 
For a list of known bugs, see `http://www.percona.com/bugs/pt-slave-restart <http://www.percona.com/bugs/pt-slave-restart>`_.
646
 
 
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:
649
 
 
650
 
 
651
 
\* Complete command-line used to run the tool
652
 
 
653
 
 
654
 
 
655
 
\* Tool "--version"
656
 
 
657
 
 
658
 
 
659
 
\* MySQL version of all servers involved
660
 
 
661
 
 
662
 
 
663
 
\* Output from the tool including STDERR
664
 
 
665
 
 
666
 
 
667
 
\* Input files (log/dump/config files, etc.)
668
 
 
669
 
 
670
 
 
671
 
If possible, include debugging output by running the tool with \ ``PTDEBUG``\ ;
672
 
see "ENVIRONMENT".
673
 
 
674
 
 
675
 
***********
676
 
DOWNLOADING
677
 
***********
678
 
 
679
 
 
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
682
 
command line:
683
 
 
684
 
 
685
 
.. code-block:: perl
686
 
 
687
 
    wget percona.com/get/percona-toolkit.tar.gz
688
 
 
689
 
    wget percona.com/get/percona-toolkit.rpm
690
 
 
691
 
    wget percona.com/get/percona-toolkit.deb
692
 
 
693
 
 
694
 
You can also get individual tools from the latest release:
695
 
 
696
 
 
697
 
.. code-block:: perl
698
 
 
699
 
    wget percona.com/get/TOOL
700
 
 
701
 
 
702
 
Replace \ ``TOOL``\  with the name of any tool.
703
 
 
704
 
 
705
 
*******
706
 
AUTHORS
707
 
*******
708
 
 
709
 
 
710
 
Baron Schwartz
711
 
 
712
 
 
713
 
*********************
714
 
ABOUT PERCONA TOOLKIT
715
 
*********************
716
 
 
717
 
 
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.
724
 
 
725
 
 
726
 
********************************
727
 
COPYRIGHT, LICENSE, AND WARRANTY
728
 
********************************
729
 
 
730
 
 
731
 
This program is copyright 2007-2011 Baron Schwartz, 2011 Percona Inc.
732
 
Feedback and improvements are welcome.
733
 
 
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.
737
 
 
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
742
 
licenses.
743
 
 
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.
747
 
 
748
 
 
749
 
*******
750
 
VERSION
751
 
*******
752
 
 
753
 
 
754
 
pt-slave-restart 1.0.2
755