Internals

WAL

Write-Ahead Log: append-only stream of every change PostgreSQL makes, used for durability, crash recovery, and replication.

PostgreSQL writes every modification — row inserts, updates, deletes, index changes — to the WAL before it touches the actual data files. On COMMIT, the relevant WAL records are flushed to disk; only then is the transaction durable. If the server crashes, recovery replays WAL forward from the last checkpoint.

WAL is also the basis for replication. A standby server streams WAL records from the primary and replays them in order, producing an identical copy of the database. Logical replication decodes the same stream into row-level change events that downstream systems can subscribe to.

Long-running transactions and replication slots prevent old WAL segments from being recycled. Watch pg_wal/ for unbounded growth — that almost always points back to an idle replication slot or a forgotten BEGIN.