MySQL OEM报警Increase the binlog_cache_size variable dynamically and monitor the ratio of Binlog_cache_disk_use to Binlog_cache_use .

发布时间 2023-05-26 16:51:00作者: PiscesCanon

 

Increase the binlog_cache_size variable dynamically and monitor the ratio of Binlog_cache_disk_use to Binlog_cache_use . When it reaches an acceptable level, put the corresponding value of binlog_cache_size in your my.cnf/my.ini file so the variable is set properly when the server is restarted. 

 

oem报警:

Host=xxx-mysql5
Target type=MySQL Database 
Target name=MySQL20_56 
Categories=Load 
Message=Increase the binlog_cache_size variable dynamically and monitor the ratio of Binlog_cache_disk_use to Binlog_cache_use . When it reaches an acceptable level, put the corresponding value of binlog_cache_size in your my.cnf/my.ini file so the variable is set properly when the server is restarted. 
Severity=Warning 
Event reported time=May 25, 2023 4:37:42 PM CST 
Operating System=Linux
Platform=x86_64 
Associated Incident Id=8308 
Associated Incident Status=New 
Associated Incident Owner= 
Associated Incident Acknowledged By Owner=No 
Associated Incident Priority=None 
Associated Incident Escalation Level=0 
Event Type=Metric Alert 
Event name=ReplicationMaster.activity:bin_log_use_exceeding_disk_cache_mem_limits 
Metric Group=ReplicationMaster.activity
Metric=bin_log_use_exceeding_disk_cache_mem_limits
Metric value=34.48275862068966
Key Value= 
Rule Name=南方自定义规则集,为严重度量预警创建意外事件 
Rule Owner=SYSMAN 
Update Details:
Increase the binlog_cache_size variable dynamically and monitor the ratio of Binlog_cache_disk_use to Binlog_cache_use . When it reaches an acceptable level, put the corresponding value of binlog_cache_size in your my.cnf/my.ini file so the variable is set properly when the server is restarted.
Incident created by rule (Name = 南方自定义规则集, 为严重度量预警创建意外事件; Owner = SYSMAN).

 

原因是跑脚本导致的,MySQL数据库的autocommit是关闭的。

 

来看一个概念:

当在服务器上启用二进制日志记录时( log_bin系统变量设置为 ON),如果服务器支持任何事务存储引擎,则会为每个客户端分配 binary log cache。如果事务的数据超出了 binary log cache 的空间,超出的数据将存储在一个临时文件中。

提交每个事务后,通过清除 binary log cache 并截断临时文件(如果使用)来重置 binary log cache。

其中,binary log cache 的大小有参数 binlog_cache_size 控制,默认大小32768,单位 bytes。

 

通过"show status like 'binlog_%';"来查看启动期间二进制日志的缓存使用情况:

(root@localhost 16:06:46) [(none)](856)> show status like 'binlog_%';
+----------------------------+--------+
| Variable_name              | Value  |
+----------------------------+--------+
| Binlog_cache_disk_use      | 9      |
| Binlog_cache_use           | 515943 |
| Binlog_stmt_cache_disk_use | 0      |
| Binlog_stmt_cache_use      | 2984   |
+----------------------------+--------+

 

 

Binlog_cache_disk_use使用 binary log cache 但超过值 binlog_cache_size 并使用临时文件存储来自事务的语句的事务数。

Binlog_cache_use:使用 binary log cache 的事务数。

Binlog_stmt_cache_disk_use使用 binary log cache 但超过值 binlog_stmt_cache_size 并使用临时文件存储这些语句的非事务语句数。

Binlog_stmt_cache_use:使用 binary log cache 的非事务语句数。

 

对MySQL服务器来说,Binlog_cache_disk_use/Binlog_cache_use 的比率越低越好,说明对当前事务的 binary log cache 是基本够用的。

这次报警是因为初始化业务数据跑脚本,而自动提交是关闭导致的,属于特殊情况因此的 Binlog_cache_disk_use 增大。

可以通过增加 binlog_cache_size 的大小减少 Binlog_cache_disk_use ,因为属于特殊情况并非日常业务导致的 Binlog_cache_disk_use 增大,不考虑该方案。

或者关闭临时在会话级别设置autocommit = on,我尝试了一下本来大概2~3min跑完的脚本硬是跑了22min。不推荐。

知道原因直接忽略即可。

当然如果日常业务导致 Binlog_cache_disk_use/Binlog_cache_use 的比率偏大,可以调整 binlog_cache_size 大小知道比率降到可接受范围后,再将 binlog_cache_size 设置到my.cnf参数文件中。

 

目前除了重启MySQL实例外不知道如何重置"show status like 'binlog_%'"的值。

防爬虫:https://www.cnblogs.com/PiscesCanon/p/17435202.html