生产环境遇到 MySQL 数据页损坏问题如何解决
1问题背景
四月份的时候,遇到一次实例异常 crash 的问题。当时数据库自动重启,未对生产造成影响,未做处理,但是还是记录了下错误信息,错误日志中有如下信息:
1 2 3 4 5 | InnoDB: End of page dump InnoDB: Page may be an index page where index id is 8196 2023-04-11T07:57:42.508371+08:00 0 [ERROR] [FATAL] InnoDB: Apparent corruption of an index page [page id: space=3859, page number=842530] to be written to data file. We intentionally crash the server to prevent corrupt data from ending up in data files. 2023-04-11 07:57:42 0x7fe4d42cf080 InnoDB: Assertion failure in thread 140620788985984 in file ut0ut.cc line 921 InnoDB: We intentionally generate a memory trap. |
因为当时自动恢复了,并未重视这个问题,然后六月份的时候实例又 crash 了。查看报错信息,报错信息如下:
1 2 3 4 | 2023-06-23T04:32:36.538380+08:00 0 [ERROR] InnoDB: Probable data corruption on page 673268. Original record on that page; (compact record)2023-06-23T04:32:36.538426+08:00 0 [ERROR] InnoDB: Cannot find the dir slot for this record on that page; (compact record)2023-06-23 04:32:36 0x7fe2bf68f080 InnoDB: Assertion failure in thread 140611850662016 in file page0page.cc line 153 InnoDB: We intentionally generate a memory trap. |
两次的报错信息很相似,出现一次是偶然,两次就值得重视了。虽然之前很幸运未对生产造成影响,但是如果后面哪一天异常了导致实例无法启动,那不就是妥妥的一个生产故障嘛,作为 DBA 要有忧患意识,必须要提前准备好应对之策,针对此类问题,该如何排查以及解决?通过查阅资料和向前辈请教,也算有所收获,想着如果有其他同学遇到类似问题也可作为参考,于是有了此文。
2问题分析
一般来说,数据页损坏,错误日志中都会显示具体的 page number,其他情况暂不考虑。在此前提下,根据实例状态可以将数据页损坏分为以下两种场景: