innodb_log_file_size

本文涉及的产品
RDS MySQL DuckDB 分析主实例,集群系列 4核8GB
简介: 如何修改 5.7 Stop the MySQL server and make sure that it shuts down without errors. Edit my.cnf to change the log file configuration.

如何修改 5.7

  • Stop the MySQL server and make sure that it shuts down without errors.
  • Edit my.cnf to change the log file configuration. To change the log file size, configure innodb_log_file_size. To increase the number of log files, configure innodb_log_files_in_group.
  • Start the MySQL server again.

If InnoDB detects that the innodb_log_file_size differs from the redo log file size, it writes a log checkpoint, closes and removes the old log files, creates new log files at the requested size, and opens the new log file.

上面这段话取自mysql5.7官方手册。

  • 确保干净的关闭数据库
  • 修改my.cnf 文件innodb_log_file_size,innodb_log_files_in_group
  • 启动数据库

调整redo log 大小官方 guidelines

  • Make your redo log files big, even as big as the buffer pool. When InnoDB has written the redo log files full, it must write the modified contents of the buffer pool to disk in a checkpoint. Small redo log files cause many unnecessary disk writes. Although historically big redo log files caused lengthy recovery times, recovery is now much faster and you can confidently use large redo log files.
  • Consider increasing the size of the log buffer. A large log buffer enables large transactions to run without a need to write the log to disk before the transactions commit. Thus, if you have transactions that update, insert, or delete many rows, making the log buffer larger saves disk I/O. Log buffer size is configured using the innodb_log_buffer_size configuration option.

这是官方给出的两条guidelines,大意是redo log越大越好,甚至可以配置到和buffer pool一样的大小。过小的redo log会带来许多不必要磁盘写入。事实上来看,确实redo log files大有许多的好处,带来的坏处就是系统一旦崩溃,恢复的时间比较长。同时考虑调整innodb_log_buffer_size参数来支持处理大事物的能力。

官方的说法比较模糊,现实中也不可能调整redo log files至 buff pool的大小,我们实际上需要更为精确的计算方法。

具体的计算方法

选取业务高峰期计算产生的日志大小,redo log 的大小最少应该承载一个小时的业务日志。

计算lsn( log sequence number)

mysql> pager grep sequence;
PAGER set to 'grep sequence'
mysql> show engine innodb status\G select sleep(60); show engine innodb status\G;
Log sequence number 2133421300
1 row in set (0.00 sec)

1 row in set (1 min 0.00 sec)

Log sequence number 2160035601
1 row in set (0.00 sec)

mysql> select (2160035601-2133421300)/1024/1024 as MB_per_min;
+-------------+
| MB_per_min  |
+-------------+
| 25.38137531 |
+-------------+
1 row in set (0.00 sec)

一个小时的日志量是1500M,默认innodb_log_files_in_group =2,则一个innodb_log_file_size =750M。我们一般取2的整数倍,所以
innodb_log_files_in_group =2
innodb_log_file_size =1024M

对于写入很频繁的数据库,设置比较大redo log file 是一个比较明智的措施。

网上有很多说法可以去计算 Innodb_os_log_written( Innodb_os_log_written is the number of bytes written to the redo logs)的大小,实际上 Innodb_os_log_written一般都是lsn的几倍,建议还是使用lsn计算,具体信息可以参考链接:
link

有个有趣的现象innodb_buffer_pool_instances这个值比较大时,实际上会产生比较多的log,这时可以调高logsize大小。
image

参考链接:
link

相关实践学习
通过日志服务实现云资源OSS的安全审计
本实验介绍如何通过日志服务实现云资源OSS的安全审计。
相关文章
|
3月前
|
算法 搜索推荐 JavaScript
基于python智能推荐算法的全屋定制系统
本研究聚焦基于智能推荐算法的全屋定制平台网站设计,旨在解决消费者在个性化定制中面临的选择难题。通过整合Django、Vue、Python与MySQL等技术,构建集家装设计、材料推荐、家具搭配于一体的一站式智能服务平台,提升用户体验与行业数字化水平。
|
8月前
|
存储 虚拟化 iOS开发
VMware ESXi 7.0U3v macOS Unlocker & OEM BIOS 2.7 标准版和厂商定制版
VMware ESXi 7.0U3v macOS Unlocker & OEM BIOS 2.7 标准版和厂商定制版
278 0
VMware ESXi 7.0U3v macOS Unlocker & OEM BIOS 2.7 标准版和厂商定制版
|
移动开发 前端开发 JavaScript
HTML5 Canvas详解及应用
HTML5 Canvas 允许通过 JavaScript 在网页上动态绘制图形、动画等视觉内容。首先在 HTML 中定义 `<canvas>` 元素,并通过 JavaScript 获取画布上下文进行绘制。常见方法包括绘制矩形、路径、圆形和文本,以及处理图像和创建动画效果。适用于游戏开发、数据可视化、图像编辑和动态图形展示等多种应用场景。需要注意性能优化、无状态绘制及自行处理事件等问题。
|
Java Android开发
Android 设置系统时区的源码追踪
Android 设置系统时区的源码追踪
339 1
|
缓存 编译器 测试技术
简化 CMake 多平台兼容性处理:高效开发的秘诀
简化 CMake 多平台兼容性处理:高效开发的秘诀
536 0
java Map删除值为null的元素
java Map删除值为null的元素
368 0
|
测试技术 数据库连接 Python
|
机器学习/深度学习 并行计算 PyTorch
pytorch使用Horovod进行分布式训练
pytorch使用Horovod进行分布式训练
465 0
|
存储 SQL 消息中间件
一篇文章搞懂数据仓库:数据仓库架构-Lambda和Kappa对比
一篇文章搞懂数据仓库:数据仓库架构-Lambda和Kappa对比
一篇文章搞懂数据仓库:数据仓库架构-Lambda和Kappa对比
|
存储 SQL 算法
炸锅了,MySQL表500W行,居然有人不做分区?
炸锅了,MySQL表500W行,居然有人不做分区?
1480 0
炸锅了,MySQL表500W行,居然有人不做分区?