How to calculate a good InnoDB log file size

Peter wrote a post a while ago about choosing a good InnoDB log file size.  Not to pick on Peter, but the post actually kind of talks about a lot of things and then doesn’t tell you how to choose a good log file size!  So I thought I’d clarify it a little.

The basic point is that your log file needs to be big enough to let InnoDB optimize its I/O, but not so big that recovery takes a long time.  That much Peter covered really well.  But how do you choose that size? I’ll show you a rule of thumb that works pretty well.

In most cases, when people give you a formula for choosing a configuration setting, you should look at it with skepticism.  But in this case you can calculate a reasonable value, believe it or not.  Run these queries at your server’s peak usage time:

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 84 3836410803
1 row in set (0.06 sec)
1 row in set (1 min 0.00 sec)
Log sequence number 84 3838334638
1 row in set (0.05 sec)

Notice the log sequence number. That’s the total number of bytes written to the transaction log. So, now you can see how many MB have been written to the log in one minute. (The technique I showed here works on all versions of MySQL. In 5.0 and newer, you can just watch Innodb_os_log_written(可参考这里) from SHOW GLOBAL STATUS, too.)

mysql> select (3838334638 - 3836410803) / 1024 / 1024 as MB_per_min;
+------------+
| MB_per_min |
+------------+
| 1.83471203 |
+------------+

As a rough rule of thumb, you can make the log big enough that it can hold at most an hour or so of logs. That’s generally plenty of data for InnoDB to work with; an hour’s worth is more than enough so that it can reorder the writes to use sequential I/O during the flushing and checkpointing process. At this rate, this server could use about 110 MB of logs, total. Round it up to 128 for good measure. Since there are two log files by default, divide that in half, and now you can set

innodb_log_file_size=64M

Does that look surprisingly small? It might. I commonly see log file sizes in the gigabyte ranges. But that’s generally a mistake. The server I used for the measurements above is a big one doing a lot of work, not a toy. Log file sizes can’t be left at the default 5MB for any real workload, but they often don’t need to be as big as you might think, either.

If this rule-of-thumb calculation ends up showing you that your log file size ought to be many gigabytes, well, you have a more active write workload. Perhaps you’re inserting a lot of big rows or something. In this case you might want to make the log smaller so you don’t end up with GB of logs. But also realize this: the recovery time depends not only on the total log file size, but the number of entries in it. If you’re writing huge entries to the log, fewer log entries will fit into a given log file size, which will generally make recovery faster than you might expect with a big log.

However, most of the time when I run this calculation, I end up finding that the log file size needs to be a lot smaller than it’s configured to be. In part that’s because InnoDB’s log entries are very compact. The other reason is that the common advice to size the logs as a fraction of the buffer pool size is just wrong.

One final note: huge buffer pools or really unusual workloads may require bigger (or smaller!) log sizes. This is where formulas break down and judgment and experience are needed. But this “rule of thumb” is generally a good sane place to start.

参考:

http://www.percona.com/blog/2008/11/21/how-to-calculate-a-good-innodb-log-file-size/

时间: 2024-10-10 01:12:43

How to calculate a good InnoDB log file size的相关文章

InnoDB log file 设置多大合适?

简介: 数据库的东西,往往一个参数就牵涉N多知识点.所以简单的说一下.大家都知道innodb是支持事务的存储引擎.事务的四个特性ACID即原子性(atomicity),一致性(consistency),隔离性(isolation),持久性(durability).其中原子性,一致性,持久性通过redo log 和 undo来实现.redo log称为重做日志,用来保证事务的原子性和持久性.undo log用来保证事务的一致性. 当事务提交时,必须先将该事务的所有日志写入到重做日志文件(redo

InnoDB: Error: log file .\ib_logfile0 is of different size 0 10485760 bytes

启动WAMP Server的时候报例如以下的错误: 140618 23:12:32 [Note] Plugin 'FEDERATED' is disabled. 140618 23:12:32 InnoDB: The InnoDB memory heap is disabled 140618 23:12:32 InnoDB: Mutexes and rw_locks use Windows interlocked functions 140618 23:12:32 InnoDB: Compres

报错问题:InnoDB: Error: log file ./ib_logfile0 is of different size

在使用xtrabackup对mysql执行备份操作的时候,出现下面的报错:.....................xtrabackup: innodb_log_file_size = 50331648InnoDB: Error: log file ./ib_logfile0 is of different size 33554432 bytesInnoDB: than specified in the .cnf file 50331648 bytes! 解决办法:可以计算一下33554432的

mariadb:InnoDB: Error: log file ./ib_logfile0 is of different size 0 5242880 bytes

mariadb 启动中 InnoDB: Error: log file ./ib_logfile0 is of different size 0 起因:线上正在运行的系统,因为需要调整性能,变更了my.cnf参数的innodb_log_file_size大小,重启MySQL时err日志输出如下InnoDB: Error: log file ./ib_logfile0 is of different size 0 xxxx bytes 停掉mariadb 解决办法:移除原有ib_logfile#m

Mysql启动报错解决方案:Failed to open log (file './mysql-bin.000901', errno 2)

ps -ef|grep mysql 发现里边没有mysql进程,于是进行重启. service mysqld start报错 查看错误日志 tail -100 /usr/local/mysql/var/iZ11yohng9aZ.err(主机名.err) 180223 15:31:51 mysqld_safe Starting mysqld daemon with databases from /usr/local/mysql/var 180223 15:31:51 InnoDB: The Inn

Linux/Unix shell 监控Oracle告警日志(monitor alter log file)

使用shell脚本实现对Oracle数据库的监控与管理将大大简化DBA的工作负担,如常见的对实例的监控,监听的监控,告警日志的监控,以及数据库的备份,AWR report的自动邮件等.本文给出Linux 下使用 shell 脚本来监控 Oracle 告警日志(monitor alter log file). Linux Shell的相关参考:        Linux/Unix shell 脚本中调用SQL,RMAN脚本        Linux/Unix shell sql 之间传递变量   

RAC 性能分析 - 'log file sync' 等待事件

简介 本文主要讨论 RAC 数据库中的'log file sync' 等待事件.RAC 数据库中的'log file sync' 等待事件要比单机数据库中的'log file sync' 等待事件复杂,主要原因是由于RAC 数据库需要将SCN同步到所有实例. 首先,回顾一下单机数据库中的'log file sync' 等待事件,当user session 提交(commit)时,user session会通知LGWR进程将redo buffer中的信息写入到redo log file,当LGWR

eclipse启动出现“An Error has Occurred. See the log file”解决方法

最近在启动eclipse时出现了“An Error has Occurred. See the log file”的错误,点击确定后也不能启动eclipse.查看log文件,出现类似: java.lang.ClassNotFoundException: javax.xml.parsers.SAXParserFactory at java.net.URLClassLoader$1.run(Unknown Source) at java.security.AccessController.doPri

Oracle db file parallel write 和 log file parallel write 等待事件

一. db file parallel write等待事件 引自如下blog: http://oradbpedia.com/wiki/Wait_Events_-_db_file_parallel_write db文件并行写 db文件并行写等待事件属于Oracle数据库写入程序(DBWR)进程,因为它是将块从SGA写入数据文件的唯一进程.当是写入时,DBWR进程编译一组脏块,将批处理交给操作系统,并等待db文件并行写事件以完成I / O.虽然用户会话从来没有遇到db文件并行写等待事件,但这并不意味