# Write-Ahead Log (WAL)

> A log the database writes each change to first. Then a crash loses nothing.

**Field:** Software Development  
**Category:** Databases  
**Also known as:** WAL, Write-Ahead Logging, Redo Log, Transaction Log

## Think of it like

Think of it like a diary you write in first. If you get called away, it says what you meant to do.

## Definition

A write-ahead log is a file where a database writes each change before doing it. The change goes to the end of the log first, which is fast. Only then does the database say the change is saved. Later, it copies the change into its main data files. If the machine crashes, the database reads the log and finishes the work.

## Example

PostgreSQL writes every change to its WAL before its tables. After a power cut, it replays the WAL and loses no saved order.

## Why it matters

It is how a database keeps saved changes safe through a crash. Copies of the log also feed backups and replicas.

## Common mistake

Putting the log on a slow or full disk. Every save waits on the log, so the whole database slows.

## Three principles

- **Log first.** Write the change to the log first.
- **Then the data.** Main files are updated later.
- **Replay on crash.** The log finishes unfinished work.

## Related terms

- [Database Transaction](https://learn.benibix.com/term/development/transaction)
- [Atomicity, Consistency, Isolation, Durability (ACID)](https://learn.benibix.com/term/development/acid)
- [Database Replication](https://learn.benibix.com/term/development/database-replication)
- [PostgreSQL](https://learn.benibix.com/term/development/postgresql)
- [Change Data Capture (CDC)](https://learn.benibix.com/term/data/change-data-capture)

![A change arrives at a database. Step one, lit up, writes it to the end of a log file on disk. Step two marks the change as saved and answers the app. Step three, later, copies the change into the main data files. A crash marker sits between steps two and three, with a note that after a restart the database replays the log, so the change is not lost.](https://learn.benibix.com/diagrams/dev3-wal.svg)

---

Source: https://learn.benibix.com/term/development/write-ahead-log
Author: Behnia Zarei (a developer in Vienna, Austria, who builds and teaches data, AI and business intelligence at BENIBIX)
Publisher: BENIBIX Learn (https://learn.benibix.com/)
Last updated: 2026-11-19
Licence: CC BY 4.0 (https://creativecommons.org/licenses/by/4.0/). Quote freely with attribution.
