This articleneeds additional citations forverification. Please helpimprove this article byadding citations to reliable sources. Unsourced material may be challenged and removed. Find sources: "Write-ahead logging" – news ·newspapers ·books ·scholar ·JSTOR(June 2022) (Learn how and when to remove this message) |
Incomputer science,write-ahead logging (WAL) is a family of techniques for providingatomicity anddurability (two of theACID properties) indatabase systems.[1]
A write ahead log is an append-only auxiliary disk-resident structure used for crash and transaction recovery. The changes are first recorded in the log, which must be written tostable storage, before the changes are written to the database.[2]
The main functionality of a write-ahead log can be summarized as:[3]
In a system using WAL, all modifications are written to alog before they are applied. Usually both redo and undo information is stored in the log.
The purpose of this can be illustrated by an example. Imagine a program that is in the middle of performing some operation when the machine it is running on loses power. Upon restart, that program might need to know whether the operation it was performing succeeded, succeeded partially, or failed. If a write-ahead log is used, the program can check this log and compare what it was supposed to be doing when it unexpectedly lost power to what was actually done. On the basis of this comparison, the program could decide to undo what it had started, complete what it had started, or keep things as they are.
After a certain amount of operations, the program should perform acheckpoint, writing all the changes specified in the WAL to the database and clearing the log.
WAL allows updates of a database to be donein-place. Another way to implement atomic updates is withshadow paging, which is not in-place. The main advantage of doing updates in-place is that it reduces the need to modify indexes and block lists.
Modernfile systems typically use a variant of WAL for at least file systemmetadata; this is calledjournaling.