Write-Ahead Logging
Subject: Computer and Technology noun /ˌraɪt.əˈhɛd ˈlɔː.ɡɪŋ/ 1 definition
- database-systems
- crash-recovery
- storage-engines
- data-durability
-
Definition (noun)
Entry #63 · UpdatedWrite-Ahead Logging (WAL) is a data-integrity and crash-recovery technique in which every state modification is recorded in an append-only log on persistent storage before the corresponding changes are written to primary data files or a transaction commit is acknowledged. By converting random in-place disk updates into fast sequential writes and ensuring log entries are flushed first via system calls such as
fsync, it guarantees atomicity and durability across unexpected crashes or power failures. Its core boundary is that the log serves as a temporary, ordered recovery journal rather than a permanent replacement for main storage, so systems must periodically perform checkpoints to flush dirty in-memory pages and truncate obsolete log segments.Common Forms
Physical Logging: Records exact byte-level or page-level before-images and after-images of modified storage blocks, making crash recovery straightforward and idempotent at the cost of larger log volumes.
Logical Logging: Records high-level mutation operations—such as SQL statements or key-value commands like
PUTandDELETE—yielding compact logs suitable for replication and LSM-tree storage engines, though requiring careful handling of partial multi-step updates.Physiological Logging: Combines physical page addressing with logical operations applied within a single page, as used in the ARIES recovery algorithm, minimizing log size while keeping per-page recovery atomic and independent.
Example
When a banking application commits an
UPDATEtransferring $500 between accounts in PostgreSQL, the database appends the WAL records to disk and waits forfsyncconfirmation before reporting success, even though the modified table pages still reside only in the in-memory buffer pool. If the server loses power before the next checkpoint writes those dirty pages to the main data files, PostgreSQL replays the WAL from the last checkpoint on startup to restore the committed transfer without data loss.