Skip to main content
Definition Website Computer and Technology

Write-Ahead Logging

Subject: Computer and Technology noun /ˌraɪt.əˈhɛd ˈlɔː.ɡɪŋ/ 1 definition

  1. Definition (noun)

    Entry #63 · Updated

    Write-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 PUT and DELETE—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 UPDATE transferring $500 between accounts in PostgreSQL, the database appends the WAL records to disk and waits for fsync confirmation 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.