Reference · Cheat sheet

Durability: redo & undo logs

The one-page compressed essence: log first, pages later — redo rolls forward, undo rolls back.

Lesson: 0007Context: InnoDB, MySQL 8.0+

The one idea

Write-ahead logging

At COMMIT, only the small sequential redo append must be durable. Data pages stay dirty in the buffer pool and flush later. Log first, pages later — cheap and crash-safe.

Two logs, opposite jobs

LogDirectionUsed for
redoroll forwardcrash recovery — replay committed-but-unflushed changes
undoroll backROLLBACK + MVCC old-version reads (0005)

Mnemonic: redo = re-do committed work after a crash; undo = un-do uncommitted work (and remember old rows for readers).

The durability dial

innodb_flush_log_at_trx_commit:

ValueAt commitMax loss
1 (default)write + fsync redonothing — full ACID
2write to OS cache; fsync ~1s≤1s on OS/power crash only (mysqld crash safe)
0write + fsync ~1s (not at commit)≤1s even on mysqld crash

Vocabulary

buffer poolin-memory cache of data/index pages
dirty pagemodified page not yet written to the data files
LSNlog sequence number — redo's ever-growing byte counter
checkpointhow far dirty pages are guaranteed flushed; redo before it can be reused

Inspect it

SHOW VARIABLES LIKE 'innodb_flush_log_at_trx_commit'; -- 1 = full ACID SHOW ENGINE INNODB STATUS\G -- LOG section: LSN, "Log flushed up to", checkpoint START TRANSACTION; UPDATE …; ROLLBACK; -- undo restores the old value

Source: MySQL 8.0 Manual — Redo Log · Undo Logs · flush_log_at_trx_commit · All lessons