About
Write-Ahead Logging (WAL) is a rollback journal implementation.
This implementation writes change directly to the rollback journal whereas the traditional rollback journal writes changes to the original database.
This rollback journal implementation has become the more prominent one because it enables non-blocking read and write.
Process
The WAL represents a ledger of the changes the database plans to make to the database file (tables, indexes,…)
After a crash (or not), when the daemon first starts up, the process compares:
- the data in the WAL.
- the data in the database file.
to perform a sort of replication. It will:
- rolls back any database file that is not committed in the WAL
- apply any change on the database file that is committed in the WAL but isn’t in the database file
Implementation
The Write-Ahead log implements transactions atomicity by:
- preserving the original data
- appending the changes into a separate WAL file.
- commiting occurs by appending a special record into the WAL.
Non blocking - Read Write
As the COMMIT occurs without writing to the original data file, Read and write can then occurs simultaneously. Ie:
- Read from the original database file
- and write to the WAL
This means that :
- read (query) are non-blocking. Readers and writers of data do not block one another.
- multi-version read consistency can be provided