mysql数据库磁盘io高的排查

来源:这里教程网 时间:2026-03-01 15:08:06 作者:

     最近,数据库会报磁盘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 |  | update | insert ignore into `xxxxannotations` (`trace_  |
2528  |xxxn |  172.xxxx : 37270  | xxxx | Query |  | update | insert ignore into `xxxxannotations` (`trace_id`, `s
2530  | xxxx |  172.xxxx : 44210  | xxxx | Query |  | update | insert into `xxxx_spans` (`trace_id`, `id`, `debug`, `start_ts`, `name
2531  |xxxx |  172.xxxx : 45910  | xxxx | Query |  | query end | insert ignore into `xxxx_annotations` 4' ' , - 1408108278 8031 ) |
2532  | xxx |  172.xxxx : 58890  | xxxx | Sleep |  | | NULL

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

mysql> show engine innodb status \G
 
---TRANSACTION  1557551308 , not started flushing log
 
---TRANSACTION  1557551309 , not started flushing log
 
---TRANSACTION  1557551310 , not started flushing log
 
---TRANSACTION  1557551311 , not started flushing log
 
---TRANSACTION  1557551313 , not started flushing log
 
---TRANSACTION  1557551304 , 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  |
+----------------------+----------+
row in set ( 0.00  sec)

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

   继续分析:

mysql> show engine innodb status \G
--------
FILE I/O
--------
..........
Pending flushes (fsync) log:  1 ; buffer pool:  0
pending preads,  pending pwrites
................
 
 
LOG
---
Log sequence number  988322448590
Log flushed up to  988322444468
Pages flushed up to  988311239867
Last checkpoint at  988309561881
pending log writes,  pending chkp writes
23371463  log i/o 's done,  132.33 log 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不高的问题消失。

相关推荐