WAL & Recovery
What survives if the machine dies after COMMIT: the write-ahead log, checkpoints, redo, undo and the restart sequence — with a crash button.
COMMIT returns, the machine dies, the dirty page was never written. The naive fix — flush every dirty page at commit — costs random 8 KB writes per changed byte and still leaves torn pages. The write-ahead log appends a description of each change to a sequential file, fsyncs it at COMMIT, and lets data pages be written whenever convenient. LSNs order everything; checkpoints let the log be truncated.
On restart the engine has a log and a set of page images that lag behind it by an unknown amount. Recovery finds the last checkpoint, scans the log forward to learn which transactions committed, replays every change whose page does not yet have it (redo, made idempotent by page LSNs), rolls back the transactions that never committed (undo — or, in PostgreSQL, nothing), and opens for business.