innodb_log_file_size

本文涉及的产品
云数据库 RDS MySQL,集群系列 2核4GB
推荐场景:
搭建个人博客
RDS MySQL Serverless 基础系列,0.5-2RCU 50GB
云数据库 RDS PostgreSQL,集群系列 2核4GB
简介: 如何修改 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

相关实践学习
日志服务之使用Nginx模式采集日志
本文介绍如何通过日志服务控制台创建Nginx模式的Logtail配置快速采集Nginx日志并进行多维度分析。
相关文章
|
7月前
|
关系型数据库 MySQL
MySQL 报错 [ERROR] [FATAL] InnoDB: Table flags are 0 in the data dictionary but the flags in file
MySQL 报错 [ERROR] [FATAL] InnoDB: Table flags are 0 in the data dictionary but the flags in file
967 0
|
存储 SQL 缓存
【MySQL】change buffer,buffer pool,redo log,bin log,undo log的作用
【MySQL】change buffer,buffer pool,redo log,bin log,undo log的作用
154 0
|
Oracle 前端开发 关系型数据库
log file sync 和 log file parallel write等待事件的区别和联系
log file parallel write 和log file sync这两个等待事件关系密切,很多人对这两个等待事件有一些误解,我们先来看看Oracle官方文档的解释:
166 0
|
存储 关系型数据库 MySQL
【MySQL】innodb_log_file_size=256M,是干什么的?底层原理是什么?
【MySQL】innodb_log_file_size=256M,是干什么的?底层原理是什么?
343 0
|
开发工具
|
开发工具
|
关系型数据库 Oracle
|
关系型数据库
|
监控 调度