FAQ系列 | 复制线程长时间Opening tables

简介: FAQ系列 | 复制线程长时间Opening tables

0、导读

在slave上,发现SQL thread长时间处于Opening tables状态

1、问题描述

朋友的数据库,做了主从replication复制。在slave实例上,SQL thread的长时间处于Opening tables状态,复制进程异常。

mysql> show processlist;

+----+-------------+-----------+------+---------+-------+----------------------------------------+------------------+

| Id | User | Host | db | Command | Time | State | Info |

+----+-------------+-----------+------+---------+-------+----------------------------------------+------------------+

| 1 | system user | | NULL | Connect | 554 | Queueing master event to the relay log | NULL |

| 2 | system user | | NULL | Connect | 59212 | Opening tables | NULL |


整个实例大概20个database,总共300G左右。

master是5.5版本,slave是5.6版本,master上执行xtrabackup全库备份后搭建的slave。

2、原因分析

我的第一反应是table cache是不是太小了,导致open table比较慢,所以才长时间处于这个状态。无论如何,先一层层排查吧。

先看下slave status(部分无用信息我隐掉了):

mysql> show slave status\G

*************************** 1. row ***************************

Slave_IO_State: Queueing master event to the relay log

Master_Log_File: master-bin.000618

Read_Master_Log_Pos: 614915856

Relay_Log_File: replicate.000008

Relay_Log_Pos: 2384117

Relay_Master_Log_File: master-bin.000617

Slave_IO_Running: Yes

Slave_SQL_Running: Yes

Replicate_Do_DB:

Replicate_Ignore_DB:

Replicate_Do_Table:

Replicate_Ignore_Table:

Replicate_Wild_Do_Table:

Replicate_Wild_Ignore_Table:

Last_Errno: 0

Last_Error:

Skip_Counter: 0

Exec_Master_Log_Pos: 252048331

Relay_Log_Space: 1438994074

Until_Condition: None

Until_Log_File:

Until_Log_Pos: 0

Seconds_Behind_Master: 59240

Master_SSL_Verify_Server_Cert: No

Last_IO_Errno: 0

Last_IO_Error:

Last_SQL_Errno: 0

Last_SQL_Error:

Replicate_Ignore_Server_Ids:

Master_Server_Id: 1

Master_UUID:

Master_Info_File: /home/mysql/master.info

SQL_Delay: 0

SQL_Remaining_Delay: NULL

Slave_SQL_Running_State: Opening tables

Master_Retry_Count: 86400

Last_IO_Error_Timestamp:

Last_SQL_Error_Timestamp:

Master_SSL_Crlpath:

Retrieved_Gtid_Set:

Executed_Gtid_Set:

Auto_Position: 0


看不出来有什么异常的。

再看下系统负载情况:

[root@localhost mysql]# vmstat -S m 1

procs -----------memory---------- ---swap-- -----io---- --system-- -----cpu-----

r b swpd free buff cache si so bi bo in cs us sy id wa st

0 2 1 19591 458 230576 0 0 11 20 0 0 0 0 100 0 0

1 1 1 19587 458 230579 0 0 2032 2528 1645 584 1 1 93 4 0

1 1 1 19583 458 230582 0 0 1664 2712 1773 461 1 1 93 4 0

0 2 1 19578 458 230585 0 0 2080 3376 1810 660 1 1 93 4 0

2 0 1 19576 458 230587 0 0 2224 1804 1634 594 1 1 94 4 0

3 1 1 19569 458 230590 0 0 1968 3488 1693 566 1 1 93 4 0

1 1 1 19567 458 230593 0 0 2016 2632 1775 515 1 1 93 4 0

[root@localhost mysql]# sar -d 1

Linux 2.6.32-431.el6.x86_64 (localhost.localdomain) 03/21/2015 _x86_64_ (24 CPU)

03:21:57 PM DEV tps rd_sec/s wr_sec/s avgrq-sz avgqu-sz await svctm %util

03:21:58 PM dev8-0 185.86 5753.54 64.65 31.30 1.20 6.48 5.08 94.44

03:21:58 PM DEV tps rd_sec/s wr_sec/s avgrq-sz avgqu-sz await svctm %util

03:21:59 PM dev8-0 197.03 6114.85 95.05 31.52 1.16 5.88 4.48 88.32

03:21:59 PM DEV tps rd_sec/s wr_sec/s avgrq-sz avgqu-sz await svctm %util

03:22:00 PM dev8-0 188.89 5882.83 88.89 31.61 1.14 6.03 5.09 96.16

03:22:00 PM DEV tps rd_sec/s wr_sec/s avgrq-sz avgqu-sz await svctm %util

03:22:01 PM dev8-0 166.00 5152.00 80.00 31.52 1.42 8.56 5.58 92.70


也看不出来异常,继续看看mysql的日志吧:

2015-04-21 14:51:04 18667 [ERROR] Native table 'performance_schema'.'objects_summary_global_by_type' has the wrong structure

2015-04-21 14:51:04 18667 [ERROR] Incorrect definition of table performance_schema.rwlock_instances: expected column 'WRITE_LOCKED_BY_THREAD_ID' at position 2 to have type bigint(20), found type int(11).

2015-04-21 14:51:04 18667 [ERROR] Native table 'performance_schema'.'setup_actors' has the wrong structure

2015-04-21 14:51:04 18667 [ERROR] Native table 'performance_schema'.'setup_objects' has the wrong structure

2015-04-21 14:51:04 18667 [ERROR] Native table 'performance_schema'.'table_io_waits_summary_by_index_usage' has the wrong structure

2015-04-21 14:51:04 18667 [ERROR] Native table 'performance_schema'.'table_io_waits_summary_by_table' has the wrong structure

2015-04-21 14:51:04 18667 [ERROR] Native table 'performance_schema'.'table_lock_waits_summary_by_table' has the wrong structure

2015-04-21 14:51:04 18667 [ERROR] Column count of mysql.threads is wrong. Expected 14, found 3. Created with MySQL 50524, now running 50623. Please use mysql_upgrade to fix this error.

2015-04-21 14:51:04 18667 [ERROR] Native table 'performance_schema'.'events_stages_current' has the wrong structure

2015-04-21 14:51:04 18667 [ERROR] Native table 'performance_schema'.'events_stages_history' has the wrong structure

2015-04-21 14:51:04 18667 [ERROR] Native table 'performance_schema'.'events_stages_history_long' has the wrong structure

…

…

2015-04-21 15:05:17 7f5997fff700 InnoDB: Error: Table "mysql"."innodb_table_stats" not found.

2015-04-21 15:05:17 7f5997fff700 InnoDB: Error: Fetch of persistent statistics requested for table "db_anonymous_info_10"."t_friend_info_3" but the required system tables mysql.innodb_table_stats and mysql.innodb_index_stats are not present or have unexpected structure. Using transient stats instead.

2015-04-21 15:05:17 7f7beb0cd700 InnoDB: Error: Table "mysql"."innodb_table_stats" not found.

2015-04-21 15:05:17 7f7beb0cd700 InnoDB: Error: Fetch of persistent statistics requested for table "db_user_trade_1"."t_trade_15" but the required system tables mysql.innodb_table_stats and mysql.innodb_index_stats are not present or have unexpected structure. Using transient stats instead.


可以看到,这个实例中,P_S(performanc_schema)库的几个表结构都异常了。另外,mysql.innodb_table_stats表也异常了,导致InnoDB表数据收集异常,然后SQL thread也跟着异常了。

3、问题解决建议

造成上面问题主要原因是,没有用正确的方式来部署slave实例。从master上用xtrabackup物理备份到slave,启动实例后,应该再执行 mysql_upgrade 升级相关表结构,确保P_S(performanc_schema)、I_S(information_schema)以及 mysql 等几个系统库表结构都升级到最新版本。

            </div>
相关实践学习
每个IT人都想学的“Web应用上云经典架构”实战
本实验从Web应用上云这个最基本的、最普遍的需求出发,帮助IT从业者们通过“阿里云Web应用上云解决方案”,了解一个企业级Web应用上云的常见架构,了解如何构建一个高可用、可扩展的企业级应用架构。
MySQL数据库入门学习
本课程通过最流行的开源数据库MySQL带你了解数据库的世界。 &nbsp; 相关的阿里云产品:云数据库RDS MySQL 版 阿里云关系型数据库RDS(Relational Database Service)是一种稳定可靠、可弹性伸缩的在线数据库服务,提供容灾、备份、恢复、迁移等方面的全套解决方案,彻底解决数据库运维的烦恼。 了解产品详情:&nbsp;https://www.aliyun.com/product/rds/mysql&nbsp;
相关文章
PowerDesigner16(PDM)pd生成数据库sql脚本
今天使用PowerDesigner16软件生成数据库脚本的时候遇到了一些问题,但是经过不懈努力最终修成正果,下面将小编的经历以及错误解决方案与大家分享。
|
设计模式 中间件 程序员
【C/C++ 奇异递归模板模式 】C++中CRTP模式(Curiously Recurring Template Pattern)的艺术和科学
【C/C++ 奇异递归模板模式 】C++中CRTP模式(Curiously Recurring Template Pattern)的艺术和科学
1353 3
|
3月前
|
人工智能 缓存 Shell
为什么越来越多人放弃 Claude Code 转而用 Pi?
之前写过两篇关于 OMP的文章,一篇聊使用,一篇聊接 DeepSeek。OMP 其实是 Pi 的一个 fork,在使用 OMP 的时候,我也一直在用 Pi。
|
10月前
|
人工智能 并行计算 监控
别再混为一谈!万字拆解内存与显存:决定你模型训练成败的硬件真相
你好,我是AI科普博主狸猫算君!本文深入浅出解析内存(RAM)与显存(VRAM)的本质区别:前者是CPU的通用办公桌,后者是GPU的专属高速实验室。重点破除“大内存=能训大模型”误区,揭示显存带宽、容量为何直接决定AI训练成败,并提供监控、排错与硬件选配实战指南。(239字)
2827 2
别再混为一谈!万字拆解内存与显存:决定你模型训练成败的硬件真相
|
9月前
|
存储 缓存 监控
JVM 运行时数据区全解:从底层原理到 OOM 根因定位全链路实战
JVM运行时数据区是Java内存管理的核心,分为线程私有区域(程序计数器、虚拟机栈、本地方法栈)和线程共享区域(堆、方法区)。不同区域有明确的OOM触发规则:堆内存不足引发Java heap space异常,元空间不足导致Metaspace异常,直接内存溢出表现为Direct buffer memory错误。排查OOM需结合异常类型、堆dump、GC日志等现场数据,使用MAT等工具分析内存泄漏点。
908 1
|
3月前
|
Rust 网络协议 安全
Orbien:一个只有 5MB,却把内网穿透做得很“轻”的 Rust 工具
Orbien 是一款基于 Rust 开发的轻量高性能内网穿透工具(仅约 5MB),支持 TCP/UDP/HTTP/HTTPS/SOCKS5 隧道及 TCP/QUIC/KCP/WebSocket 多种传输协议,内置 Web 管理界面与跨平台桌面客户端,兼顾安全、易用与低资源占用。
490 0
|
3月前
|
移动开发 缓存 安全
H5页面分享失效排查:微信JS-SDK签名的配置与验证
本文记录微信JS-SDK签名的完整配置流程:服务号/安全域名/备案三个前置条件、jsapi_ticket换取与SHA1签名算法、url去hash等参数细节、debug验证三步法,并附5个真实踩坑案例。
|
8月前
|
人工智能 自然语言处理 算法
GEO时代:为何官网才是品牌价值的“压舱石”?
AI时代,官网是品牌权威的“终极信源”。Geo专家于磊提出“人性化Geo+内容交叉验证”双核心,以E-E-A-T融合、结构化数据、意图关键词、权威引用“四轮驱动”,助官网成为AI首选信源。案例显示,引用率提升210%,转化率增156%。
329 6
|
9月前
|
人工智能 前端开发 Serverless
如何用 Claude AWS配合阿里云函数计算搭建AI应用
企业核心业务在阿里云,却需调用AWS Bedrock的Claude模型?推荐用阿里云函数计算(FC)构建Serverless代理网关:安全隐藏AK/SK、弹性抗并发、网络更稳定。架构为“用户→API网关→FC→Bedrock”,百毫秒延迟,轻量高效。

热门文章

最新文章