Percona Toolkit · 复制异常修复工具 pt-slave-restart

功能

pt-slave-restart:是一个修复由于不同的错误而意外终止 slave 复制的工具,和配置参数 slave_skip_errors 功能类似。

Warning:除非知道跳过操作的影响或后果,否则不要自动跳过任何错误,会影响数据一致性。

原理

它以指数变化的睡眠时间定期巡视检查 slave 复制状态,初始默认 1s,并试图跳过导致错误的语句。

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
Usage: pt-slave-restart [OPTIONS] [DSN]
Options:

--always Start slaves even when there is no error(不建议使用此参数)
--ask-pass Prompt for a password when connecting to MySQL
--charset=s -A Default character set
--[no]check-relay-log Check the last relay log file and position before
checking for slave errors (default yes)
--config=A 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
--database=s -D Database to use
--defaults-file=s -F Only read mysql options from the given file
--error-length=i Max length of error message to print
--error-numbers=h Only restart this comma-separated list of errors
--error-text=s Only restart errors that match this pattern
--help Show help and exit
--host=s -h Connect to host
--log=s Print all output to this file when daemonized
--master-uuid=s When using GTID, an empty transaction should be
created in order to skip it
--max-sleep=f Maximum sleep seconds (default 64)
--min-sleep=f The minimum time pt-slave-restart will sleep before
polling the slave again (default 0.015625)
--monitor Whether to monitor the slave (default)
--password=s -p Password to use when connecting
--pid=s Create the given PID file
--port=i -P Port number to use for connection
--quiet -q Suppresses normal output (disables --verbose)
--recurse=i Watch slaves of the specified server, up to the
specified number of servers deep in the hierarchy (
default 0)

使用

1
2
3
./pt-slave-restart -uroot -p'xx' --error-numbers=1062
2019-05-04T00:59:09 P=3306,h=x.x.x.x,p=...,u=root relay-bin.000005 369 1032
2019-05-04T00:59:20 P=3306,h=x.x.x.x,p=...,u=root relay-bin.000005 726 1032