mysql数据库磁盘io高的排查是怎样的,相信很多没有经验的人对此束手无策,为此本文总结了问题出现的原因和解决方法,通过这篇文章希望你能解决这个问题。

最近,数据库会报磁盘IO高的告警,但是cpu不高。

故障
● 主机名称: xxxx
● 告警信息: Disk I/O is overloaded on xxxx
● 告警时间: 2020.04.10-13:09:06
● 主机地址: xxxxxx
● 当前状态: 36.14 %

数据库磁盘io高时,执行的sql如下:

2527| xxxx |172.xxxx:35072| xxxx | Query |0| update | insert ignore into `xxxxannotations` (`trace_|

|2528|xxxn |172.xxxx:37270| xxxx | Query |0| update | insert ignore into `xxxxannotations` (`trace_id`, `s

|2530| xxxx |172.xxxx:44210| xxxx | Query |0| update | insert into `xxxx_spans` (`trace_id`, `id`, `debug`, `start_ts`, `name

|2531|xxxx |172.xxxx:45910| xxxx | Query |0| query end | insert ignore into `xxxx_annotations`4',', -1408108278,8031) |

|2532| xxx |172.xxxx:58890| xxxx | Sleep |0| | NULL

也就是数据库会批量的执行insert ignore into 语句。

mysql> show engine innodb status \G

---TRANSACTION1557551308, not started flushing log

---TRANSACTION1557551309, not started flushing log

---TRANSACTION1557551310, not started flushing log

---TRANSACTION1557551311, not started flushing log

---TRANSACTION1557551313, not started flushing log

---TRANSACTION1557551304, not started flushing log

............


可以看到,每个事务都在flushing log中,说明刷redo log比较慢。可能是redo log 比较小。

mysql> show variables like'%innodb_log_file_size%';

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

| Variable_name | Value |

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

| innodb_log_file_size |50331648|

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

1row in set (0.00sec)

事实证明,innodb_log_file_size确实比较小,才50M,建议增大至2个4G。

继续分析:

mysql> show engine innodb status \G

--------

FILE I/O

--------

..........

Pending flushes (fsync) log:1; buffer pool:0

1pending preads,0pending pwrites

................

LOG

---

Log sequence number988322448590

Log flushed up to988322444468

Pages flushed up to988311239867

Last checkpoint at988309561881

1pending log writes,0pending chkp writes

23371463log i/o's done,132.33log i/o's/second

上述看到log thread 挂起的fsync()操作数据为1,说明log thread刷盘有等待。

另外,last checkpoint落后于log flushed up to太多,接近于redo log文件的大小,这时会触发innodb疯狂刷redo,从而导致磁盘io高,对性能影响非常糟糕。

还有,这个数据库的innodb buffer pool也很小,使用的默认值为128M,也需要调大。

优化方法:

设置innodb_log_file_size=4G,设置innodb_buffer_pool_size=4G。

经过观察,数据库磁盘io高、cpu不高的问题消失。

看完上述内容,你们掌握mysql数据库磁盘io高的排查是怎样的的方法了吗?如果还想学到更多技能或想了解更多相关内容,欢迎关注亿速云行业资讯频道,感谢各位的阅读!