前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >pt-online-schema-change连踩三个坑!

pt-online-schema-change连踩三个坑!

作者头像
AsiaYe
发布2021-05-10 17:06:04
3.2K2
发布2021-05-10 17:06:04
举报
文章被收录于专栏:DBA随笔DBA随笔

//

pt-online-schema-change错误排查一例

//

今天在线上遇到一个PT工具相关的问题,问题是pt-osc这个在线改表工具报出来的。简单记录了一下排查的过程。

01

问题描述

线上的pt工具版本是3.1.0版本的,改表过程中的PT命令如下:

代码语言:javascript
复制
pt-online-schema-change --alter  "  ADD COLUMN xxx "  
--charset utf8 
--chunk-time 0.5 
--critical-load Threads_connected:1200,Threads_running:100 
--max-load Threads_connected:1200,Threads_running:100 
--lock-wait-timeout 200
--check-replication-filters 
--check-interval 5 
--alter-foreign-keys-method=drop_swap 
--execute --max-lag 3 
--check-slave-lag h=10.69.16.129  
--user=automan_common --password=xxxxx 
--host=10.xx.xx.xxx
--port=5602 D=db_name,t=table_name

报错如下:

代码语言:javascript
复制
Unknown option: lock-wait-timeout
Usage: pt-online-schema-change [OPTIONS] DSN

Errors in command-line arguments:
  * Error parsing options
  * Specify only one DSN on the command line
  * The DSN must specify a database (D) and a table (t)

pt-online-schema-change alters a table's structure without blocking reads or
writes.  Specify the database and table in the DSN.  Do not use this tool before
reading its documentation and checking your backups carefully.  For more
details, please use the --help option, or try 'pt-online-schema-change' for complete
documentation.

看这个报错信息,可以看到是pt工具无法解析lock-wait-timeout这个参数的值了。查看了一下官方文档:

https://www.percona.com/doc/percona-toolkit/2.1/pt-online-schema-change.html

这个是2.1版本的官方文档,里面针对lock-wait-time有介绍,它是一个内置的参数,介绍如下:

代码语言:javascript
复制
--lock-wait-timeout

type: int; default: 1

Set the session value of innodb_lock_wait_timeout. This option helps guard against
 long lock waits if the data-copy queries become slow for some reason. Setting this 
option dynamically requires the InnoDB plugin, so this works only on newer InnoDB and
 MySQL versions. If the setting’s current value is greater than the specified value, 
and the tool cannot set the value as desired, then it prints a warning. If the tool 
cannot set the value but the current value is less than or equal to the desired 
value, there is no error.

它指代的是pt工具在操作过程中,MySQL中的锁等待时间。

在pt 3.0版本以及更新的版本中,这个变量不复存在了,如果想要设置这个参数,可以通过一个叫--set-var的参数来设置,这个参数在pt 3.0以上的说明文档中有介绍:

https://www.percona.com/doc/percona-toolkit/3.0/pt-online-schema-change.html

代码语言:javascript
复制
--set-vars
type: Array

Set the MySQL variables in this comma-separated list of variable=value pairs.

By default, the tool sets:

wait_timeout=10000
innodb_lock_wait_timeout=1
lock_wait_timeout=60

Variables specified on the command line override these defaults. For example, specifying --set-vars wait_timeout=500 overrides the default value of 10000.

这两个版本设置该参数的方法分别如下:

pt2.x版本:

--lock-wait-timeout 60

pt3.x版本:

--set-var lock_wait_timeout=60

到这里,将这个lock_wait_timeout的参数写法进行修改,这个问题就算解决了。

上线之后,发现了一个新的问题,且看。

02

PT3.1版本的外键问题

在使用--set-vars设置了lock-wait-timeout参数之后,利用pt-osc执行命令的时候,又发现了一个新的问题,问题如下:

代码语言:javascript
复制
error in MySQL that makes the server to die when trying to rename a table with FKs. 
See https://bugs.mysql.com/bug.php?id=96145
Since pt-online-schema change needs to rename the old <-> new tables as the final step, 
and the requested table has FKs, it cannot be executed under the current MySQL version\n'

从这个描述中,可以看到,问题的反馈是这个要修改的目标表拥有外键,但是实际上,这个表的定义SQL中,没有外键,所以我怀疑是一个bug,在官方网站上找了下,果然,找到了bug的地址:

https://jira.percona.com/browse/PT-1782

在pt 3.1.0的版本,在特定MariaDB10.2和MySQL 8版本下,确实存在这个bug,就是表没有外键的情况下也会报外键的错误,解决的方案,从大家的反馈中可以看到,是通过pt版本降级,使用pt3.0.x版本来解决这个问题。

但是版本降级,好像又不太合适,最新的pt工具已经到了3.3版本。所以我尝试了下最新的版本,看看这个问题是否得到了解决,下载了一个pt 3.3.0的版本。

果然,问题得到了解决,不报外键的错误了。

但是...新问题又来了。。。

03

3.3版本的新问题---连接失败

pt-osc的3.3版本出现了一个新问题,就是pt工具的账号密码都正确配置的情况下,报错账号密码错误,无法连接MySQL,提示如下报错:

代码语言:javascript
复制
b"Cannot connect to MySQL: DBI connect('finance_guarantee;host=xxx.xxx.xxx.xxx;
charset=utf8;mysql_read_default_group=client','automan_common',...) failed: 
Host 'xxx.xxx.xxx.xxx' is not allowed to connect to this MySQL server at pt-online-schema-change line 2345.\n"

经过一番排查,发现了新的bug jira地址:

https://jira.percona.com/browse/PT-1911?jql=project%20%3D%20PT%20AND%20component%20%3D%20pt-online-schema-change

bug描述中显示,3.3版本的pt工具存在下面的问题:

1、如果端口不是3306

则不能通过--port=4306 这种方法;

而是需要写成:P=4306

代码语言:javascript
复制
错误写法:
pt-online-schema-change --port=3366 D=sre_test,t=candles
正确写法:
pt-online-schema-change D=sre_test,t=candles,P=3366

2、如果端口是3306,则可以通过--port的方法来写。

代码语言:javascript
复制
正确写法:
pt-online-schema-change --port=3306 D=sre_test,t=candles
正确写法:
pt-online-schema-change D=sre_test,t=candles,P=3366

基于上面这些小问题,最后我将pt的版本回退到了3.0.11,这个版本经过测试,是一个比较稳定的版本。没有上述问题。

不得不说,这个pt工具确实是小问题比较多。。。

但是这并不妨碍它的使用,毕竟要想同时兼容MariaDB、Percona Server、MySQL Server三个版本的服务,确实在细节上要考虑的事情比较多。它强大的功能,确实让DBA爱不释手。

好在官方文档开诚布公,有详细的bug 记录,可以让你很快的解决遇到的问题。这一点我觉得做的很好。

今天就到这里吧,希望能对大家有帮助。

本文参与 腾讯云自媒体分享计划,分享自微信公众号。
原始发表:2021-04-27,如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 DBA随笔 微信公众号,前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体分享计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
相关产品与服务
云数据库 SQL Server
腾讯云数据库 SQL Server (TencentDB for SQL Server)是业界最常用的商用数据库之一,对基于 Windows 架构的应用程序具有完美的支持。TencentDB for SQL Server 拥有微软正版授权,可持续为用户提供最新的功能,避免未授权使用软件的风险。具有即开即用、稳定可靠、安全运行、弹性扩缩等特点。
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档