Bug #13494 Log size differences create possibility of corruption
Submitted: 26 Sep 2005 18:35 Modified: 4 Oct 2012 6:17
Reporter: C.J. Adams-Collier Email Updates:
Status: Closed Impact on me:
None 
Category:MySQL Server: InnoDB storage engine Severity:S4 (Feature request)
Version:4.0.24_Debian-10-log OS:Linux (Debian GNU)
Assigned to: Marko Mäkelä
Triage: D5 (Feature request)

[26 Sep 2005 18:35] C.J. Adams-Collier
Description:
/etc/mysql/my.cnf contains a an innodb log size different than on-disk log file size:
set-variable = innodb_log_file_size=20M

$ ls -ld /var/lib/mysql/ib_logfile0
-rw-rw----  1 mysql mysql 5242880 2005-09-18 05:10 /var/lib/mysql/ib_logfile0

$ sudo mysqld
InnoDB: Error: log file ./ib_logfile0 is of different size 0 5242880 bytes
InnoDB: than specified in the .cnf file 0 20971520 bytes!
050926 10:58:25 Can't init databases
050926 10:58:25 Aborting

050926 10:58:25  InnoDB: Warning: shutting down a not properly started
                 InnoDB: or created database!
050926 10:58:25 mysqld: Shutdown Complete

Syslog contents:

---

Sep 26 11:07:55 norseth mysqld[15355]: InnoDB: Error: log file ./ib_logfile0 is of different size 0 5242880 bytes
Sep 26 11:07:55 norseth mysqld[15355]: InnoDB: than specified in the .cnf file 0 20971520 bytes!
Sep 26 11:07:55 norseth mysqld[15355]: 050926 11:07:55 Can't init databases
Sep 26 11:07:55 norseth mysqld[15355]: 050926 11:07:55 Aborting
Sep 26 11:07:55 norseth mysqld[15355]: 
Sep 26 11:07:55 norseth mysqld[15355]: 050926 11:07:55  InnoDB: Warning: shutting down a not properly started
Sep 26 11:07:55 norseth mysqld[15355]:                  InnoDB: or created database!
Sep 26 11:07:55 norseth mysqld[15355]: 050926 11:07:55 /usr/sbin/mysqld: Shutdown Complete

---

The solution is to stop MySQL, change the line in my.cnf:
set-variable = innodb_log_file_size=5M

and re-start the daemon.

After the daemon re-starts, stop it, move the log file out of the way, change the size in the my.cnf file, and re-start the daemon.

This will re-set the size of the log file to whatever is in the config file.

There is a lot of room for slip-up here.

How to repeat:
See above

Suggested fix:
There should be some sort of wrapper around the process.  JamesDay tells me that this is one of the largest problems causing innodb corruption.  If the log file is damaged, the database has a great potential to become corrupted.
[26 Sep 2005 19:50] Heikki Tuuri
Hi!

In your example case, no corruption can occur. InnoDB simply refuses to start with a log file of a wrong size.

Further corruption CAN occur if mysqld crashes and the user tries to resolve the problem by deleting old ib_logfiles, or replacing them with wrong ib_logfiles. But then the database is probably corrupt anyway, because otherwise the user would have been happy with the automatic crash recovery of InnoDB.

The main problem that I have observed is diagnosing the crashes that result from wrong logfiles. It is often difficult to tell why mysqld segfaulted.

The following feature would solve this diagnosis problem:

http://www.innodb.com/todo.php
"
Add more safety checks that would prevent one from using wrong ib_logfiles with ibdata files. InnoDB could once per minute stamp the current lsn to the trx system page in ibdata1, and at a startup compare the stamp to the log files, as well as to the shutdown lsn stamps in the ibdata files.
"

Regards,

Heikki
[30 Sep 2008 20:31] C.J. Adams-Collier
Thanks Heikki,

Has this feature been implemented since last we spoke?

Cheers,

C.J.
[11 Nov 2010 22:24] Calvin Sun
bug#16533 is marked as a dup.
[15 Apr 2012 20:32] Jon Brewer
This procedure also works for 5.5.15-log on Windows 7 Home Premium.
Thanks for solution!
Regards Jon Brewer
[4 Oct 2012 6:17] Marko Mäkelä
This error will be fixed in MySQL 5.6.8.

In the case of a size mismatch, we would apply the old logs and then rewrite new ones. Also, with this change, the log file creation and database startup should be more crash-safe. Previously, if mysqld was killed while it was creating the files, it would not recover, and you would have to delete all files before restarting.

There does seem to be a possibility of corruption before the fix in MySQL 5.6.8. If you start InnoDB with a smaller innodb_log_files_in_group (the configured number of ib_logfile* files), then InnoDB may treat the log as corrupted. The ib_logfile* files are treated as if they were concatenated together. If you 'truncate' the logs by reducing the number of files that InnoDB tries to open, all bets are off.
[30 Dec 2012 7:27] Shane Bester
http://bugs.mysql.com/bug.php?id=67993 is a duplicate of this