为什么有时候binlog文件会很大于max_binlog_size以及max_binlog_cache_size
问题描述
线上一个很有意思的现象,发现binlog文件大小是15G,查看了参数max_binlog_size是1073741824[1G], max_binlog_cache_size是21474836480[20G]。那么为什么会文件大小会超过max_binlog_file_size的设置。这个问题比较好理解,如果是大事务呢?那么这里有一个小问题,binlog里面是以event为单位来记录的,那么事务有可能跨binlog吗?使用BEGIN;***;***;commit进行测试
第二个问题,以上面的设置为例,在文件快到1G的时候,如果来了一个大事务,这个大事务接近20G,那么是不是可以任务binlog文件的最大可能值是接近1G+20G=21G呢,因为超过max_binlog_cache_size就会报错了。这个也是可以测试下的。
实验证明
问题1:实验测试
root@test10:39:24>set global max_binlog_size=4096; root@test10:48:23>begin;
Query OK, 0 rows affected (0.00 sec) root@test10:48:39>insert into testb select * from testa limit 32;
Query OK, 32 rows affected (0.00 sec)
Records: 32 Duplicates: 0 Warnings: 0 root@test10:49:05>insert into testb select * from testa limit 32;
Query OK, 32 rows affected (0.00 sec)
Records: 32 Duplicates: 0 Warnings: 0 root@test10:49:10>insert into testb select * from testa limit 32;
Query OK, 32 rows affected (0.00 sec)
Records: 32 Duplicates: 0 Warnings: 0 root@test10:49:14>insert into testb select * from testa limit 32;
Query OK, 32 rows affected (0.00 sec)
Records: 32 Duplicates: 0 Warnings: 0 root@test10:49:18>commit;
Query OK, 0 rows affected (0.00 sec)
# at 3994 -- 上一个event结束的地方
#190130 10:49:14 server id 21036055 end_log_pos 4064 CRC32 0x64e8a1c6 Rows_query
# insert into testb select * from testa limit 32
# at 4064
#190130 10:49:14 server id 21036055 end_log_pos 4113 CRC32 0x7ef21b8c Table_map: `test`.`testb` mapped to number 11496
# at 4113
#190130 10:49:14 server id 21036055 end_log_pos 4692 CRC32 0xfc3f78bd Write_rows: table id 11496 flags: STMT_END_F -- 这已经是下一个insert 语句了,在一个binlog文件中,说明binlog是以事务为单位来进行切割的,不是事务里面的单个sql语句,这也是比较好理解的,因为事务只有执行完了, 才能在内存中生成完整的binlog,才存在刷盘的操作。
问题2:实验测试
root@test11:01:52>set global max_binlog_cache_size=4096;
root@test11:15:20>insert into testb select * from testb limit 200; -- 3.9K Jan 30 11:15 mysql-bin.003691
root@test11:15:28>insert into testb select * from testb limit 460; -- 12K Jan 30 11:16 mysql-bin.003691
root@test11:17:34>insert into testb select * from testb limit 470; -- 最大就是在460到470之间
ERROR 1197 (HY000): Multi-statement transaction required more than 'max_binlog_cache_size' bytes of storage; increase this mysqld variable and try again
这个实验说明binlog文件最大应该是max_binlog_size + max_binlog_cache_size的和,但是max_binlog_cache_size在文件大小上可能比实际设置的值要大,见下问题。所有严格来讲应该是大于两者的和的。
在实验的过程中遇见一个新问题
root@test11:07:21>insert into testb select * from testb limit 400;
# at 331
#190130 11:07:32 server id 21036055 end_log_pos 402 CRC32 0x62bb0a5e Rows_query
# insert into testb select * from testb limit 400
# at 402
#190130 11:07:32 server id 21036055 end_log_pos 451 CRC32 0x3177b22e Table_map: `test`.`testb` mapped to number 11496
# at 451
#190130 11:07:32 server id 21036055 end_log_pos 7286 CRC32 0x35efff16 Write_rows: table id 11496 flags: STMT_END_F
能正常插入证明内存中产生的binlog应该是小于4096的,但是实际在binlog中看见的确实7286,明显是比4094大的,为啥会这样呢,在从内存中把binlog落盘的过程中做了什么处理吗?
root@test11:21:01>show create table testb\G
*************************** 1. row ***************************
Table: testb
Create Table: CREATE TABLE `testb` (
`a` bigint(20) DEFAULT NULL,
`b` bigint(20) DEFAULT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci
1 row in set (0.00 sec)
root@test11:24:10>select version();
+---------------+
| version() |
+---------------+
| 5.7.21-21-log |
+---------------+
1 row in set (0.00 sec)
以上是表结构以及MySQL的版本
如有任何问题,欢迎指正。
参考文献:
https://dev.mysql.com/doc/refman/5.7/en/replication-options-binary-log.html#sysvar_max_binlog_size
为什么有时候binlog文件会很大于max_binlog_size以及max_binlog_cache_size的更多相关文章
- shell脚本实例一,移动文件夹中大于2000B的文件到另一个文件夹
shell脚本能帮我们简化linux下的一些工作,现在有个需求,把TMPA文件夹下大于2000B的文件都移动到TMPB下 #! /bin/bash function movefiles() { ` d ...
- Python 查找binlog文件
经常需要在 binlog 中查找一些日志信息,于是写了一个简单的脚本.对于非常巨大的 binlog 文件,该脚本可能会速度慢,毕竟还是用的 list,暂时没想到好办法. 详细看代码: #/usr/bi ...
- 通过 mysqlbinlog 和 grep 命令定位binlog文件中指定操作
1.binlog日志基本知识 MySQL的二进制日志binlog可以说是MySQL最重要的日志,它记录了所有的DDL和DML语句(除了数据查询语句select),以事件形式记录,还包含语句所执行的消耗 ...
- MySQL在线删除多余的binlog文件
如果你的MySQL搭建了主从同步 , 或者数据库开启了log-bin日志(MySQL默认开启) , 那么随着时间的推移 , 你的数据库data 目录下会产生大量的日志文件 ll /opt/mysql/ ...
- mysql5.5 物理删除binlog文件导致的故障
故障现象: 中午12点多,一套主从集群的主库因为没有配置大页内存,发布时导致OOM,MYSQL实例重启了,然后MHA发生了切换.切换过程正常.切换后需要把原master配置成新master的slave ...
- 用Mysqlbinlog备份BinLog文件
默认情况下, mysqlbinlog读取二进制文件[BinLog]并以文本的方式呈现[text format].mysqlbinlog可以直接地从本地读取Log,也可以读取远程的Log[--read- ...
- 查看binlog文件的2种方式
1.使用show binlog events a.获取binlog文件列表 mysql> show binary logs; +------------------+-----------+ | ...
- 查看MySQL日志数据binlog文件
binlog介绍 binlog,即二进制日志,它记录了数据库上的所有改变. 改变数据库的SQL语句执行结束时,将在binlog的末尾写入一条记录,同时通知语句解析器,语句执行完毕. binlog格式 ...
- Linux 上通过binlog文件 恢复mysql 数据库详细步骤
一.binlog 介绍 服务器的二进制日志记录着该数据库的所有增删改的操作日志(前提是要在自己的服务器上开启binlog),还包括了这些操作的执行时间.为了显示这些二进制内容,我们可以使用mysqlb ...
随机推荐
- java断言 assert
关于assert的用法网上教程很多,这里就不说了,只演示一下运行时开启断言的方法. public class A{ public static void main(String[] args){ Cl ...
- 小Y的轮回之路——攒机装机、B150装win7
两个月前,陪伴我5年多的小Y(ideapad-y460N卡)突然大伤元气,硬盘跪了,显示屏也黑了一小块.本着经济实惠凑合用的态度换了个320G的硬盘,没想过几天显示屏情况加重,出现无数个红绿相间的线条 ...
- SQL Server ->> 高可用与灾难恢复(HADR)技术 -- AlwaysOn可用性组(理论篇)
因为篇幅原因,AlwaysOn可用性组被拆成了两部分:理论部分和实战部分.而实战部分又被拆成了准备工作和AlwaysOn可用性组搭建. 三篇文章各自的链接: SQL Server ->> ...
- 学习笔记---Javascript事件Event、IE浏览器下的拖拽效果
学习笔记---Javascript事件Event.IE浏览器下的拖拽效果 1. 关于event常用属性有returnValue(是否允许事件处理继续进行, false为停止继续操作).srcE ...
- windows下安装jmeter
windows下安装jmeter post by rocdk890 / 2012-8-19 16:08 Sunday windows技术 发表评论 JMeter是Apache软件基金会的产品,用于对静 ...
- Surrounded Regions [未完成]
思路完全一样 AC的代码: class Solution { private: struct Point { int x, y; Point(int _x, int _y):x(_x), y(_y) ...
- antd Grid
import { Row, Col } from 'antd'; <Row type="flex" //内容布局(左靠齐,右靠齐,居中) justify="star ...
- C# Winform App 获取当前路径
直接双击执行 D:\test1.exeSystem.Diagnostics.Process.GetCurrentProcess().MainModule.FileName D:\Test1.exe S ...
- c++中左值的含义
<<cpp primer plus 6th edition>>中的原文(Chapter 8 Adventures in Functions): What is an lvalu ...
- dba_tables、all_tables、user_tables
本文摘抄自:http://blog.csdn.net/daxiang12092205/article/details/42921063 dba_tables : 系统里所有的表的信息,需要DBA权限才 ...