Reference · Cheat sheet

The WAL & checkpoints

Lesson 0009 distilled — log before data, checkpoints, the durability dial, and why Postgres needs one log where InnoDB needs two. Built to print.

From lesson 0009Context: PostgreSQL current

The one idea

Log before data: a change's WAL record is flushed to disk before its data page. At commit, flush only the WAL (one sequential file), not the scattered dirty pages.

Recovery = REDO / roll forward: replay WAL to re-apply committed changes not yet in the data files.

Checkpoints

Periodically flush all dirty data pages + write a checkpoint record.

→ Recovery replays WAL only from the last checkpoint; older WAL can be recycled.

Trade-off: frequent = fast recovery, more I/O spikes; infrequent = cheaper runtime, longer replay + more WAL.

synchronous_commit (durability dial)

on (default): commit waits for the WAL flush → full durability.

off: commit returns before flush → faster, but a crash can lose a small window of recent commitsno corruption, DB stays consistent.

fsync=off, which does risk corruption.

One log vs two (the keystone)

Postgres WAL = redo only. No undo log — old versions live in the heap (never update in place, 0001) and VACUUM reclaims them. That design choice is what removes the need for undo.

Postgres vs InnoDB

JobInnoDBPostgres
Durability (redo)redo logWAL
MVCC old rowsundo logheap
ReclaimpurgeVACUUM
Flush dialflush_log_at_trx_commitsynchronous_commit

Peek at it

SHOW wal_level; · SHOW synchronous_commit;

SELECT pg_current_wal_lsn(); — current WAL write position (advances as you write).

CHECKPOINT; — force dirty pages to disk (superuser).