Home

WriteAheadLogging

Write-Ahead Logging (WAL) is a technique used in databases and some file systems to ensure durability and atomicity of writes. In WAL, all modifications are first recorded in a log before they are applied to the actual data files. The log is written sequentially and durably, and only then are the data pages updated. This arrangement allows the system to recover to a consistent state after a crash by replaying the log to redo committed transactions and to undo any uncommitted work.

Operations are described by log records that capture the intent and details of changes. The log is

WAL is a core component in many database systems, including PostgreSQL, and is also used in SQLite’s

Trade-offs include increased write-ahead latency due to the need to persist log records before data pages are

flushed
to
stable
storage
before
the
corresponding
data
pages
are
updated.
On
transaction
commit,
a
commit
record
is
written
and
flushed,
guaranteeing
durability.
If
a
crash
occurs,
recovery
scans
the
WAL
to
reapply
necessary
changes
and
to
roll
back
incomplete
transactions,
restoring
atomicity
and
consistency.
write-ahead
mode.
Variants
exist,
such
as
physical
WAL,
which
records
changes
to
data
blocks,
and
logical
WAL,
which
records
higher-level
operations
for
purposes
like
logical
decoding
and
replication.
WAL
also
enables
robust
replication
by
shipping
log
records
to
standby
instances.
updated,
but
this
is
typically
offset
by
improved
crash
resilience
and
the
ability
to
optimize
data-page
I/O
through
sequential
logging.
Recovery
performance
depends
on
the
length
and
structure
of
the
WAL,
and
some
systems
offer
both
physical
and
logical
logging
to
support
both
durability
and
replication
needs.