← all systems · see it in The System
Write-ahead logging
| boundary | Inside: the log (records with sequence numbers, threaded per transaction, in a volatile buffer and on stable storage), the write-ahead rule that orders log writes before page writes and before commit is acknowledged, the force (flush) that makes records stable, group commit, checkpoints, and the restart and media recovery that read the log back. Outside: the database pages and files whose changes are logged, the operating system's page cache and the devices beneath it (which may acknowledge writes they have not made), the applications and people who rely on committed work, replicas that receive the log, and attackers or investigators who read it. |
| nested level | A technique and the structure it keeps (rung 12): built from log records, the log buffer, stable storage and the recovery manager; part of a database's transaction machinery and of journaling file systems; carried on computer hardware and the operating system's write path; reused in replicated state machines and, at the application level, in event sourcing. |
| scale | technological |
From the walk
For about 20 years PostgreSQL trusted a second try: when Linux reported that saving data to disk had failed, PostgreSQL asked again, and the second request said 'done' because the system had already marked the unsaved pages as clean. PostgreSQL then threw away the log it would have needed to recover, losing data; the fix was to crash on purpose and rebuild from the log instead (src:rebello-2020-fsync).
Definition. In computer science, write-ahead logging (WAL) is a family of techniques for providing atomicity and durability in database systems: a system records what it is about to change in an append-only log on stable storage before the change reaches its home location, and after a crash reads the log back to rebuild its state. Walked as both the practice (the rule, the recovery methods, the people and programs that keep it) and the structure it works on (the log itself: records ordered by log sequence numbers on stable storage). Definition drawn from the encyclopedia entry (Wikipedia, CC BY-SA).
On this page: Properties 2 · Measures 30 · Open contentions 3 · Cross-scale patterns 21 · Valence partners 14 · Partners and parts 63 · Notes 4 · Layers 54 · Sources 37
Properties published scienceour proposal
Sourced fields, and our own readings.
| born at | 1978 (the principle named, Gray 1978, as cited) |
| born precision | ±10 years (contested: C-4628) |
Measures (30) published science
| checkpoint interval (Sprite LFS) | 30 s |
| SQLite automatic checkpoint threshold | 1000 pages of WAL |
| ext3 checkpoint point in a 50 MB journal | 25 MB written |
| share of disk bandwidth for new data (Sprite LFS) | 65-75 % (rest to cleaning) |
| utilisation threshold of cleaned segments to beat Unix FFS | < 0.8 (< 0.5 to beat an improved FFS) fraction live |
| write cost of cleaning (LFS model) | 2/(1-u) multiple of ideal write time, u = fraction live in segments cleaned |
| data journaling write amplification (ext3 data mode) | 2 writes per data block (journal, then home) |
| transaction failure rate (1983) | 10-100 per minute |
| share of transactions that abort | 3 % |
| system failure frequency (assumed, 1983) | several per week |
| target restart recovery time (1983) | a few minutes |
| media failure frequency (1983) | 1-2 per year |
| media recovery time (1983) | about 1 hour |
| operator errors | about 1 per year |
| SSDs misbehaving under power fault | 13 of 15 devices |
| power-fault cycles to device death (worst SSD) | 136 cycles (another lost a third of its blocks after 8) |
| crash vulnerabilities found in 11 applications | 60 vulnerabilities |
| years PostgreSQL used fsync incorrectly | 20 years |
| log flush share of commit latency (group commit, LeanStore) | about 8 % |
| 4 KB random write latency, enterprise NVMe SSD | 11 µs |
| 90th-percentile commit latency, autonomous commit (YCSB) | 175 µs |
| log insert throughput, Aether (single socket) | over 1.8 GB/s |
| servers tolerated failing in a five-server Raft cluster | 2 servers |
| PostgreSQL page write unit | 8192 bytes = 16 sectors |
| event-sourced systems characterised | 19 systems, 25 engineers count |
| confidence of schema inference from one WAL write size (some sizes) | 100 % |
| BigFoot throughput cost (concurrent workloads, small segments) | up to 7 % decrease |
| worst recovery recorded in production (one long transaction, SQL Server) | 12 hours |
| recovery time with constant time recovery (Azure SQL, production) | under 3 min for 99.999% of recovery cases |
| write-behind logging gains on NVM | 1.3x throughput; recovery > 100x faster; storage 1.5x smaller ratio |
Open contentions (3) open contention
Where sources or readings disagree. Both stay on the map.
- C-4609 Are the two crash-safety modes of the SQLite database (the rollback journal and the write-ahead log, which records changes before making them) different techniques, or one principle?
booked: The map keeps both readings side by side and rules on neither.
the other reading: Haerder and Reuter's taxonomy: the rollback journal obeys the WAL principle (undo information flushed before the in-place write, src:sqlite-atomic-commit 3.7 before 3.9) and is an undo-only log of a steal-and-force design ('The temporary log file contains only UNDO data (owing to FORCE)'), so WAL mode is a move from undo-only to redo-only inside one family; the placement of SQLite's two modes on the steal/force grid is the specialist's reading, not stated in a source read - C-4616 When a program tells a solid-state drive to save data for sure, is the data really safe if the power fails?
booked: The map keeps both readings side by side and rules on neither.
the other reading: enterprise NVMe SSDs make their DRAM buffer durable with capacitors, so fsync is 'free' and durable (Nguyen et al. 2025) - C-4628 Where does the 'write-ahead' rule (record a change before making it) come from: a 1978 paper, older bookkeeping practice, or IBM's earlier database systems?
booked: The map keeps both readings side by side and rules on neither.
the other reading: the bookkeeping rule of never altering the books, kept by the first computer systems on cards and tape and restored by logging (Gray 1981's own history); logging and recovery in earlier systems that ARIES compares (IMS, System R's shadow-page recovery); their dates not read here; IBM's own name and practice: 'Log-Write-Ahead (LWA) protocols' in IMS/VS, a user option while the log was on tape and mandatory from IMS/VS V1.3 (Peterson and Strickland 1983, read in sections); the version dates are not given in the parts read
Cross-scale patterns seen here (21) our proposal
Shapes that recur when the same kind of problem is solved at different scales, and how each shows in Write-ahead logging. Each links to every other system that shows it.
- borrowed-then-held (structural)
The history the system needs for recovery was first kept by the medium: on cards and tape the old master was never updated, 'due in part to good accounting practices but also due to the technical aspects of cards and tape: writing a new tape was easier than re-writing the old tape.' Direct-access di - same role, different builds (structural)
One job, leaving storage in a state a crash cannot break, done by different builds: write-ahead logging with in-place updates, shadow paging (System R), copy-on-write trees up to the root (ZFS, Btrfs, LMDB), soft updates that order writes so the worst case is a storage leak, and the log-structured f - same shape, opposite sign (structural)
One mechanism, a side file of page images with a single commit step, run with its sign reversed. SQLite's rollback journal copies the original content aside and writes changes into the database; commit is deleting the journal. In WAL mode 'the WAL approach inverts this': the original stays in the da - templating (structural)
The write-ahead rule and its recovery method are reused unchanged across systems: ARIES in Db2, SQL Server and 'many other database systems', applicable to persistent languages, recoverable file systems and transaction-based operating systems; file systems use 'a variant of WAL'; replicated state ma - The carry (structural)
All three faces. Overflow passed on: when the journal or WAL fills, its excess must be moved home by a checkpoint before space is reused (ext3 checkpointed at 25 MB of a 50 MB journal; SQLite at 1000 pages). The wait: each transaction waits at least one group commit round, and on NVMe SSDs 'the prim - The Payment to Entropy (structural)
Every hand-off from log to home pays a toll in device time. In Sprite LFS about 65-75% of raw bandwidth carries new data and the rest pays for cleaning (η ≈ 0.65-0.75); the model's write cost is 2/(1-u). In ext3 data journaling each block is written twice (η = 0.5 of device writes carry new data hom - trade one property for another (structural)
Several dials, each with systems settled at different points: group commit buys throughput and pays latency; the LFS checkpoint interval trades normal-running cost against roll-forward time; LFS trades cost per byte against speed ('a cost-performance trade-off'); metadata-only journals trade fault p - who opens the door (structural)
The doors recovery uses are opened from inside ahead of time: at each checkpoint the system writes the master record 'in a well-known place on stable storage' so a future restart can find where to start; followers are built to persist entries before replying; the commit path waits on a return code i - causal ceiling (partial)
What the database can know about durability is capped by the write path: 'When the operating system sends a write request to the storage hardware, there is little it can do to make sure the data has arrived at a truly non-volatile storage area.' The ceiling is set by the interface (a completion sign - holding / entrainment (partial)
ext3 groups unrelated updates into one compound transaction, so 'all traffic in a transaction is committed to disk at the same rate': the journal's commit sets the pace of every writer, synchronous or not (tangled synchrony). In ARIES the log force sets when each page may be written. The whole sets - namespace completeness (the map predicts its gaps) (partial)
Haerder and Reuter's classification scheme (propagation atomic or not, STEAL or not, FORCE or not, checkpoint type) is a small namespace into which every recovery design on this walk's shelf falls, offered as 'a simple, yet precise classification of all reasonable implementation techniques'; the pap - nested ladder (partial)
ext3's journaling modes form a ladder of guarantees: writeback 'has the weakest consistency semantics of the three modes' (metadata only); ordered adds data consistency; data journaling 'provides the same strong consistency guarantees as ordered journaling mode' by another route. So two rungs and a - red-queen (partial)
Attack-defend loop at one turn: encryption of the WAL defends against a storage adversary reading data; the adversary answers by reading the sizes of encrypted writes ('encryption alone is not sufficient'), identifying some inserted schemas with 100% confidence; BigFoot answers by padding every writ - smooth to sharp in finite time (partial)
In the LFS cleaning model the write cost 2/(1-u) rises smoothly with the live fraction u of the segments cleaned and becomes infinite at u = 1, a finite parameter: cleaning a full segment frees nothing. The authors keep the system away from it by a bimodal segment distribution. - symmetry breaking (name the cut) (partial)
Raft breaks the symmetry of equal servers by electing one leader per term ('first electing a distinguished leader'); the broken direction sets everything after: entries flow leader to followers, and a leader only appends. The election mechanism itself was not read in detail. - the whole sets the local reference (partial)
The log's single sequence of LSNs is the reference each page measures itself against: every page carries the LSN of its latest logged update, and redo compares the page's LSN with the record's to know whether to apply it. In a replicated log, the majority's log is the reference each follower's log i - Umwelt: each system carves its own slice of one shared medium (partial)
Each floor reads its own slice of one write: the application sees fsync's return code, the operating system sees a device's completion, the device sees its cache; 'there is little it can do to make sure the data has arrived'. Linux file systems mark pages clean after a failed fsync, so a later reade - cephalization (surface)
In a replicated log one leader receives client requests and manages the log for all ('giving the leader complete responsibility for managing the replicated log'); the end that meets new input first holds the processing. The input-first reason is not argued in the source; it is simplicity. - lightning (surface)
A power loss is the out-of-the-blue event after which the system is not the same: volatile buffers are gone, a page write may be torn partway (some of 16 sectors written), and the log must be read back. The lightning test on the Function rows: none of them is met only by such a discharge; all rest o - same toolkit, independent builds (surface)
Journaling appeared in IBM's JFS (1990), NTFS (1993), HFS Plus (1998) and ext3 (2001) from the same parts (a log, a commit block, checkpoints); whether the builds were independent or one idea passed on is not shown (the encyclopedia says 'subsequently implemented'). - seed (surface)
The transaction log as a small rule that opens many builds: ARIES 'is applicable not only to database management systems but also to persistent object-oriented languages, recoverable file systems and transaction-based operating systems'; the log reappears as journals, replicated logs and event store
Valence: what it trades, and with whom (14) published science
Each exchange with a neighbour, read from both sides: who gains, who pays, and what carries it.
- Human (Homo sapiens) via Human (Homo sapiens) · Write-ahead logging gain
- Computer memory via Computer hardware · Write-ahead logging mixed
- Operating system via Computer hardware · Write-ahead logging mixed
- Accounting (the field and practice) via Human (Homo sapiens) · Write-ahead logging gain
- File system via Computer hardware · Write-ahead logging gain
- Computer hardware via Computer hardware · Write-ahead logging mixed
- Database via Computer hardware · Write-ahead logging gain
- Embedded database via Computer hardware · Write-ahead logging gain
- Transaction log via Computer hardware · Write-ahead logging even
- attacker via Computer hardware · Write-ahead logging loss
- Digital forensics via Computer hardware · Write-ahead logging even
- Byzantine fault via Computer network · Write-ahead logging gain
- State machine replication via Computer network · Write-ahead logging gain
- Event streaming: the distributed log via Written record (durable external marks: texts, archives, canon) · Write-ahead logging even
Partners and parts published science
Built from / builds (10)
- Embedded database
- The log
- Log records (update, compensation, commit, abort, checkpoint)
- Log sequence number (LSN)
- Stable storage
- Restart and media recovery (analysis, redo, undo)
- Checkpoints
- Group commit
- A storage adversary against an encrypted write-ahead log
- Readers and the checkpointer over the WAL file
Sits inside / holds (3)
expressed by (18)
- Generation/Synthesis
- Recombination/Composition
- Scaffolding/Enablement (Meta-Tooling)
- Templating / Standardization
- Quality Improvement/Refinement
- Encapsulation & Modularity (Abstraction)
- Internal Coordination/Regulation
- Sensing/Scanning
- Active Experimentation / Probing (Optimal Experimental Design)
- Trail-Marking / Externalized Memory (Stigmergy)
- Quick Harm Avoidance
- Proactive Defense
- Self-Monitoring
- Validation of Effectiveness
- Enclave/Segregation
- Resilience & Repair
- Redundancy & Diversity
- Quality Control & Error Correction
floor filled by (22)
- Embedded database
- Human (Homo sapiens)
- Computer memory
- Operating system
- Device driver
- File system
- Computer hardware
- Database
- The log
- Transactions
- Solid-state drive
- State machine replication
- Consensus algorithm
- Log records (update, compensation, commit, abort, checkpoint)
- Log sequence number (LSN)
- Stable storage
- Restart and media recovery (analysis, redo, undo)
- Checkpoints
- Group commit
- Event sourcing
- Archive log
- Buffer manager
represents (1)
Kinds (7)
- ARIES
- Journaling file system
- Log-structured file system
- Replicated log (state machine replication)
- Event sourcing
- SQLite WAL mode
- LSM-tree storage engine's WAL (RocksDB, LevelDB)
wired (2)
Notes published science
- For about 20 years PostgreSQL trusted a second try: when Linux reported that saving data to disk had failed, PostgreSQL asked again, and the second request said 'done' because the system had already marked the unsaved pages as clean. PostgreSQL then threw away the log it would have needed to recover, losing data; the fix was to crash on purpose and rebuild from the log instead (src:rebello-2020-fsync).
- When researchers cut the power to 15 solid-state drives over 3,000 times, 13 of them lost data they had already reported as safely written, and one drive stopped showing up on its bus at all after 136 power cuts (src:zheng-2013-ssd).
- Jim Gray traced the database log to Hansel and Gretel: their trail of crumbs let them retrace their steps backward and let their parents follow it forward, 'the first undo and redo log', and the bird that ate the crumbs 'caused the first log failure' (src:gray-1981).
- In IBM's IMS before version 1.3 the rule at the heart of database recovery, write the log first, was a setting customers could switch off for speed; if they did and the machine crashed, the log had to be fished out of a dump of memory, and after a power failure there was no dump to fish from (src:peterson-1983-ims).
Layers
The ways it takes in its world, where they meet, and how it acts back, each from L1 (where it meets the world) up.
the boardroom (shared floors)
- L4: The write-ahead rule and commit: undo information logged before a page goes home, redo information forced before commit is acknowledged, page-LSNs to enforce it, group commit to share the force
- L5: Checkpoints and recovery: checkpoints, restart (analysis, redo by repeating history, undo with compensation records), media recovery from image copy and archive log, torn-page repair
- L6: The guarantees: atomicity and durability, restartable undo and redo, committed entries durable (on a majority, for a replicated log)
- L7: The services and people that rely on committed work: databases, file systems, replicated services, event-sourced applications, and users who see a booking stay booked
way in: Changes and commit requests from transactions
- L1: The program's requests: begin, the updates, commit or abort
- L2: The update applied to the page in the volatile buffer pool
- L3: A log record built and placed in the volatile log buffer, given its LSN
way in: Completion signals from the write path (fsync returns, device flush completions)
- L1: The media and their caches: platters, flash and the write-back caches in controllers and drives
- L2: The device's answer to a flush, which some devices give without having made the write durable
- L3: The operating system's fsync and its return code
way in: Log entries from a leader (a replicated log)
- L1: Messages between servers, subject to delay, partition, loss, duplication and reordering
- L2: Entries received and written to stable storage before the server answers
- L3: The consistency check: matching index and term mean matching logs up to there
way in: Log space and checkpoint thresholds (the log's own fullness)
- L1: The journal or WAL file as a circular buffer on storage
- L2: The log's size counted against a threshold
- L3: Readers' end marks that the checkpointer must not pass
- L4: The writer checks the checkpointer's progress and rewinds the WAL when all of it is home and unused
way in: Media failure: the archive copy and the archive log
- L1: A device whose contents are lost
- L2: The archive copy (image copy): an older state kept elsewhere
- L3: The archive log, read in sequence
way in: Settings made by administrators and designers (sync level, journaling mode, write caches)
- L1: The administrator's responsibility for the storage beneath
- L2: A file system's journaling mode chosen at mount time
- L3: A database's synchronous level: sync the log on every commit or not
way in: The restart after a crash: the log read back
- L1: Loss of power or a crash empties volatile memory
- L2: The master record at a well-known place points to the last complete checkpoint
- L3: The log read back: analysis from the begin-chkpt record the master record points to; redo from the RedoLSN (the oldest dirty page's RecLSN, which can lie before the checkpoint); undo back to the oldest loser's first record. In Sprite LFS, roll-forward reads only the log after the last checkpoint.
- L4: Analysis: which pages were dirty and which transactions were losers at the crash
way in: Torn or garbage data read back from storage
- L1: A page write cut partway by power loss: some sectors written, some not
- L2: A CRC-32C on every WAL record, checked during recovery and replication
- L3: Full page images in the WAL to restore a torn page
way out: Checkpoint, ARIES sense: a fuzzy checkpoint recorded in the log, no data pages written
- L3: the begin-chkpt LSN stored in the master record at a well-known place
- L5: begin-chkpt record, then an end-chkpt record holding the transaction table and the dirty-pages table, taken while updates go on
way out: Checkpoint, file-system and SQLite sense: logged blocks or frames copied back to their home locations, log space reclaimed
- L1: Pages written in place at their home locations
- L3: The log rewound or truncated so it does not grow without bound
- L5: Checkpointing writes journaled blocks to their fixed locations
way out: Commit acknowledged to the program and the user
- L1: The reply the user sees: the seat is booked
- L4: Commit marked and acknowledged only after the log records are durable
way out: Forcing the log to stable storage
- L1: Records on several non-volatile devices with independent failure modes
- L2: fsync and device flushes, with barriers at chosen points in a journal
- L4: The log forced up to a commit record's LSN (or a dirty page's LSN)
way out: Restart writes: redo and undo applied to pages, rollbacks logged
- L1: Dirty pages written to nonvolatile storage, still under the WAL rule
- L3: Compensation log records written for each undone update, chained so repeated restarts stay bounded
- L5: The redo pass repeats history; the undo pass rolls back losers
way out: The log shipped to replicas and followers
- L1: Entries sent to every server so every log holds the same commands in the same order
- L6: An entry is committed once replicated on a majority
way out: Write sizes visible to whoever holds the storage (unintended output)
- L1: Storage that may be compromised apart from the database
- L2: Encrypted WAL writes whose sizes follow what was written
write-ahead logging as database and storage researchers describe it: power, media and device caches at the bottom, the write path and its acknowledgements, log records with sequence numbers, the write-ahead rule and commit, checkpoints and restart recovery, the guarantees of atomicity and durability, up to the databases, file systems, replicated services and people that rely on committed work (reader's view)
- L1: Stable storage and what threatens it: disks, flash and battery- or capacitor-backed caches; power loss and crashes that empty volatile memory; the home locations where pages are updated in place
- L2: The write path and its acknowledgements: the operating system's page cache, fsync and its return code, device write caches, flush commands and barriers; the only signal that a write is durable
- L3: The log: records (update with redo and undo, compensation, commit, abort, checkpoint) with monotonically increasing log sequence numbers, threaded per transaction, appended to a volatile log buffer and forced to stable storage in sequence
- L4: The write-ahead rule and commit: undo information on the log before a page goes home; redo information forced before commit is acknowledged; page-LSNs let the buffer manager enforce it; group commit forces many commits at once
- L5: Checkpoints and recovery: checkpoints bound the log restart must read and let space be reclaimed; restart runs analysis, redo (repeating history) and undo (with compensation records); media recovery replays the archive log onto an image copy
- L6: The guarantees: atomicity and durability (ACID), restartable undo and redo, committed entries durable (in a replicated log, on a majority); what the system promises its users and what a recovery log must hold to keep the promise
- L7: What relies on committed work: databases (Db2, SQL Server, PostgreSQL, SQLite), journaling file systems, replicated services (Raft clusters), event-sourced applications, and the programmers and people who use their results without thinking about failures