问题描述

线上一个很有意思的现象,发现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的更多相关文章

  1. shell脚本实例一,移动文件夹中大于2000B的文件到另一个文件夹

    shell脚本能帮我们简化linux下的一些工作,现在有个需求,把TMPA文件夹下大于2000B的文件都移动到TMPB下 #! /bin/bash function movefiles() { ` d ...

  2. Python 查找binlog文件

    经常需要在 binlog 中查找一些日志信息,于是写了一个简单的脚本.对于非常巨大的 binlog 文件,该脚本可能会速度慢,毕竟还是用的 list,暂时没想到好办法. 详细看代码: #/usr/bi ...

  3. 通过 mysqlbinlog 和 grep 命令定位binlog文件中指定操作

    1.binlog日志基本知识 MySQL的二进制日志binlog可以说是MySQL最重要的日志,它记录了所有的DDL和DML语句(除了数据查询语句select),以事件形式记录,还包含语句所执行的消耗 ...

  4. MySQL在线删除多余的binlog文件

    如果你的MySQL搭建了主从同步 , 或者数据库开启了log-bin日志(MySQL默认开启) , 那么随着时间的推移 , 你的数据库data 目录下会产生大量的日志文件 ll /opt/mysql/ ...

  5. mysql5.5 物理删除binlog文件导致的故障

    故障现象: 中午12点多,一套主从集群的主库因为没有配置大页内存,发布时导致OOM,MYSQL实例重启了,然后MHA发生了切换.切换过程正常.切换后需要把原master配置成新master的slave ...

  6. 用Mysqlbinlog备份BinLog文件

    默认情况下, mysqlbinlog读取二进制文件[BinLog]并以文本的方式呈现[text format].mysqlbinlog可以直接地从本地读取Log,也可以读取远程的Log[--read- ...

  7. 查看binlog文件的2种方式

    1.使用show binlog events a.获取binlog文件列表 mysql> show binary logs; +------------------+-----------+ | ...

  8. 查看MySQL日志数据binlog文件

    binlog介绍 binlog,即二进制日志,它记录了数据库上的所有改变. 改变数据库的SQL语句执行结束时,将在binlog的末尾写入一条记录,同时通知语句解析器,语句执行完毕. binlog格式 ...

  9. Linux 上通过binlog文件 恢复mysql 数据库详细步骤

    一.binlog 介绍 服务器的二进制日志记录着该数据库的所有增删改的操作日志(前提是要在自己的服务器上开启binlog),还包括了这些操作的执行时间.为了显示这些二进制内容,我们可以使用mysqlb ...

随机推荐

  1. Windows API-----top level window

    原文地址: http://blog.163.com/cumt_xl/blog/static/19071504420136911838683/ Q: What is a top-level window ...

  2. 项目经验:GIS<MapWinGIS>建模第三天

    记录下GIS工程进展

  3. 【阿里云产品公测】ACE下上传文件永久存储实践

    本帖主要内容: ;$,=VB:'   在阿里云的ACE下,我是如何实现让上传的文件永久保存的? ,%"!8T   本文以PHP为例,具体知识点如下: WD# 96V   第一,扩展服务“存储 ...

  4. 139.00.009提高Github Clone速度

    @(139 - Environment Settings | 环境配置) Method 1 :SS+系统内置代理 用 git 内置代理,直接走系统中运行的代理工具中转,比如,你的 SS 本地端口是 1 ...

  5. Android碎笔录2——按键的点击变色和圆角实现

    android的Button默认写出来之后都是方形的直角,并且点击感很不明显,只要在drawable中加上一个xml就能解决这个问题: <?xml version="1.0" ...

  6. Jmeter运营活动并发测试—巧用集合点

    在运营活动测试过程中,经常需要对秒杀活动或定时抽奖活动进行并发测试.那么怎样快速便捷的模拟多用户同时参与活动,抽取奖品,进行并发测试呢?尤其是,当奖品总数N<用户总数M时,代码是否会存在奖品多发 ...

  7. Elk and nginx and redis 干货

    ELKStack ELKStack即Elasticsearch + Logstash + Kibana.日志监控和分析在保障业务稳定运行时,起到了很重要的作用.比如对nginx日志的监控分析,ngin ...

  8. Canvas杂谈

    最近在看一些关于Canvas的知识...这篇文章主要是用来记录学习中遇见的一些问题...以及难以理解的一些东西.. 转帖请注明出处:http://www.cnblogs.com/Troy-Lv5/p/ ...

  9. 关于“为什么不加friend就会提示参数过多”

    #include <iostream> using namespace std; class Complex { double real, imag; public: Complex(do ...

  10. 一、WPF 2个datagrid之间同步进度条

    页面代码 <Grid DockPanel.Dock="Left" Width="400"> <DataGrid Name="dgSo ...