Robots Atlas>ROBOTS ATLAS
Infrastructure

WAL

1992ActivePublished
Key innovation
Recording a description of each change to a sequential log on durable storage BEFORE the actual data files are modified — a commit requires only flushing the log, not every changed data page.
Category
Infrastructure
Abstraction level
Pattern
Operation level
DataServing
Use cases
Durability and crash recovery in relational databases (PostgreSQL, SQLite, Db2, SQL Server)Replication and change streaming (log shipping, logical/physical replication)Point-in-time recovery (PITR) and online backupsWrite durability in vector databases and state stores for AI systemsDurability journals in distributed storage systems and queues

How it works

1. Each modification produces a log record (WAL record) describing the change. 2. Log records are appended sequentially to the log file and flushed to durable storage (fsync) BEFORE the actual data files are changed. 3. A transaction commits the moment its commit record is durably written to the log — the changed data pages may reach disk later. 4. A single log fsync can commit many small, concurrent transactions. 5. A checkpoint transfers applied changes from the log into the actual data files and lets the old log be truncated (or archived). 6. After a crash the recovery manager replays committed changes from the log (REDO) and rolls back uncommitted ones (UNDO). WAL also enables online backups and point-in-time recovery (PITR) by archiving and replaying the log.

Problem solved

How to guarantee durability and atomicity of committed transactions despite a crash, without the costly flushing of every changed data page to disk on each commit. The naive approach (writing changes in place) loses data on a mid-write crash or forces many random disk writes.

Components

Log records (WAL records)Durable, ordered record of change intents

Sequentially appended entries describing each data change; flushed to durable storage before the data files are modified.

CheckpointBounds log size and recovery time

Operation that transfers applied changes from the log into the actual data files, allowing the old log to be truncated or archived.

Recovery manager (REDO/UNDO)Restores a consistent state after a crash

After a crash, replays changes of committed transactions from the log (REDO) and rolls back changes of uncommitted transactions (UNDO).

Implementation

Implementation pitfalls
WAL does not work over network filesystemsHigh

Shared-memory-based implementations (e.g. SQLite) require a local filesystem; WAL does not work correctly over NFS/network filesystems.

Fix:Use local storage for the WAL file; for sharing, use replication/log shipping instead of a shared filesystem.
Unbounded WAL file growthMedium

If checkpoints cannot run (e.g. long-running readers hold an old snapshot), the log grows without bound, consuming space and lengthening recovery.

Fix:Configure automatic checkpoints, limit long-running read transactions, and monitor log size.
Durability depends on correct fsyncHigh

Durability guarantees assume storage honors fsync faithfully. Lying/buffered fsync (e.g. in cheap hardware or some filesystems) can lose committed data after a power failure.

Fix:Verify that hardware/FS honors fsync; disable volatile disk write caches without battery backup, or use hardware with battery-backed caches.
Worse performance for very large transactionsLow

WAL works best for small transactions; for transactions on the order of hundreds of MB the rollback journal mode can be faster (SQLite).

Fix:For very large transactions, consider a different journaling mode or splitting work into smaller transactions.

Evolution

Original paper · 1992 · ACM Transactions on Database Systems (TODS), Vol. 17, No. 1, pp. 94–162 · C. Mohan
ARIES: A Transaction Recovery Method Supporting Fine-Granularity Locking and Partial Rollbacks Using Write-Ahead Logging
C. Mohan, Donald Haderle, Bruce Lindsay, Hamid Pirahesh, Peter Schwarz
1992
ARIES algorithm published
Inflection point

Mohan et al. (IBM) formalize a Write-Ahead Logging-based recovery method with fine-granularity locking and partial rollbacks. Used in IBM Db2, Microsoft SQL Server and others.

2010
WAL mode in SQLite 3.7.0

SQLite 3.7.0 (2010-07-21) introduces WAL mode as an alternative to the rollback journal: more concurrency (readers do not block the writer), more sequential I/O and fewer fsync() calls.

Hyperparameters (configurable axes)

Checkpoint frequencyHigh

How often the log is flushed into the data files. Less frequent checkpoints = less background I/O but a larger log and longer recovery.

Durability sync policy (fsync on commit)Critical

Whether a commit waits for the log to be durably flushed. Synchronous commit gives full durability at the cost of latency; asynchronous increases throughput at the risk of losing the most recent transactions.

Log size thresholdMedium

Maximum log size that triggers a checkpoint/truncation. Prevents excessive growth of the WAL file.

Parallelism

Parallelism level
Sequential

The log is appended sequentially, giving writes a sequential character (cheap fsync) but serializing the log stream. A single log fsync can, however, commit many concurrent transactions (group commit).

Hardware requirements

Primary

WAL is a software technique independent of accelerators; it benefits mainly from fast sequential writes to durable storage (SSD/NVMe) and efficient fsync.