DataWALredo logjournalcrash recovery

Write-ahead log

Definition

A write-ahead log (WAL) is a sequential record of changes that must reach stable storage before the data pages it describes, and before a commit is acknowledged.

In practice

Appending to one log and flushing it is far cheaper than writing every changed page to its place on disk at commit time. Data pages stay in memory and are written later, at checkpoints; after a crash, recovery starts from the last checkpoint and replays the WAL. Group commit lets one flush cover many concurrent commits, which raises throughput.

The same log does double duty: replicas apply it to stay in sync, change data capture tools read it, and point-in-time recovery replays archived segments. The cost is that the WAL disk becomes a hot path, so slow storage directly raises commit latency, and an archive or replica that falls behind can make WAL files pile up and fill the disk.

Example

Postgres writes UPDATE accounts ... as a WAL record, flushes pg_wal on COMMIT, answers the client, and writes the modified 8 KB table page minutes later at the next checkpoint.