InnoDB redo log

The redo log is the log where InnoDB first writes the content of a change before modifying a data page. At commit, only the redo log is flushed to disk, not the modified pages; the pages are written slowly from the buffer pool later. When the server restarts after a failure, InnoDB reapplies the redo log from the last checkpoint to restore committed changes. The files form a circular structure that reuses a fixed amount of space.

Key specs

ItemValue
Files (from 8.0.30)32 files (#ib_redoN) in the #innodb_redo folder of the data directory: the file being written and spare files (_tmp)
Size setting (from 8.0.30)innodb_redo_log_capacity, default 100MB. Can be changed without a restart
Files (before 8.0.30)ib_logfile0, ib_logfile1 ...
Size setting (before 8.0.30)innodb_log_file_size × innodb_log_files_in_group, a restart is required to change it
Log bufferinnodb_log_buffer_size, default 16MB
Position markerLSN (Log Sequence Number): a number that grows with the bytes written to the log
How it is flushed to disk at commitinnodb_flush_log_at_trx_commit
Record unit512-byte log blocks, mixed physical and logical (page number and the change within the page)

How it works

Figure. The circular redo log and the checkpoint

block-beta
  columns 8
  t["Redo log space (innodb_redo_log_capacity)"]:8
  c1["Reusable"]:2 c2["Checkpoint LSN"] c3["Changes to pages not yet written to disk"]:3 c4["Current LSN"] c5["Reusable"]
  class t plain
  class c1,c5 free
  class c2 muted
  class c3 hot
  class c4 slot

Diagram explanation: When a transaction modifies a page, the change goes through the log buffer and is appended at the Current LSN position. Changes before the Checkpoint LSN are already reflected in the data files, so that space is Reusable. The span between the two positions (Changes to pages not yet written to disk) is the checkpoint age, and it is the amount to reapply during restart recovery.

When space runs low. When the checkpoint age approaches the log space, the page cleaner writes dirty pages urgently to push the checkpoint forward (adaptive flushing). If it still cannot keep up, new writes stall while waiting for the checkpoint. This is why throughput drops periodically on a write-heavy server when the redo log is too small.

Choosing the size. A larger size gives flushing more room and spreads writes more evenly, but more log must be reapplied after a failure, so restart recovery takes longer. A common rule of thumb is about one hour of log at peak write load.

Relationship with undo. Changes to undo pages are also recorded in the redo log. So at restart, InnoDB first applies redo to restore even the undo log, and then rolls back uncommitted transactions using undo.

Settings and checks

SHOW VARIABLES LIKE 'innodb_redo_log_capacity';          -- from 8.0.30
SET GLOBAL innodb_redo_log_capacity = 4 * 1024 * 1024 * 1024;

-- Current LSN and checkpoint LSN (Log section)
SHOW ENGINE INNODB STATUS;

SHOW GLOBAL STATUS WHERE Variable_name IN ('Innodb_redo_log_capacity_resized', 'Innodb_os_log_written', 'Innodb_log_waits');
SELECT FILE_NAME, START_LSN, END_LSN FROM performance_schema.innodb_redo_log_files;   -- from 8.0.30

If Innodb_log_waits keeps increasing, the log buffer is too small and transactions have waited.

Comparison with other DBMSs

InnoDBPostgreSQLOracleSQL Server
NameRedo LogWALRedo Log (online redo log)Transaction Log
File structureCirculates over a fixed-size spaceAppends to 16MB segment files and recycles themCirculates over log groups, can be archivedA single file circulates in units of virtual log files (VLFs)
Before-image valuesNone (kept separately in the undo log)NoneNone (kept separately in undo)Included in the log

In the articles

NOTE The file layout and default size differ by version. The setting name changed around 8.0.30.

Related pages