8. DatabasesWAL and recovery
WAL and recovery
A write-ahead log is an append-only file where a database records every change before it applies that change to the actual data files. Committing a transaction only requires the log entry to be safely on disk, which is fast because appending to the end of a file is a sequential write; the real data pages can be updated later, in batches. If the machine crashes, the database reads the log on restart, redoes committed changes that hadn’t reached the data files and undoes anything left half-done. Almost every serious database uses one, and the same log is often streamed to replicas to keep them in sync.
In this lesson: Crash mid-transaction, then replay the log.