---
title: "Crash Recovery and Write-Ahead Logging"
description: "Durability is achieved by writing the intention to a log before touching the data pages. After a crash the system replays committed work and undoes the rest, which is how a commit can be trusted the m"
canonical: https://lightmysky.com/learn/computing/crash-recovery-and-write-ahead-logging-mt_JFPafSWOWF
source: https://lightmysky.com/learn/computing/crash-recovery-and-write-ahead-logging-mt_JFPafSWOWF.md
retrieved: 2026-09-12
---

> **Agent view.** This is the Markdown twin of the page, for tools and assistants.
> When to use this site, and the call that answers each job: https://lightmysky.com/agent-instructions.md
> API description (OpenAPI 3.1): https://lightmysky.com/openapi.json · Authentication: https://lightmysky.com/auth.md
> Pricing: https://lightmysky.com/pricing.md · Catalog: https://lightmysky.com/llms.txt · Full catalog: https://lightmysky.com/llms-full.txt
> Every machine-readable file on this domain: https://lightmysky.com/.well-known/ai-catalog.json
> Ask for Markdown with `Accept: text/markdown`, a `.md` address, or `?mode=agent`.

# Crash Recovery and Write-Ahead Logging

Durability is achieved by writing the intention to a log before touching the data pages. After a crash the system replays committed work and undoes the rest, which is how a commit can be trusted the moment it returns.

Subject: Computing · Area: Data & Databases · Ages 20 to 22
Page: https://lightmysky.com/learn/computing/crash-recovery-and-write-ahead-logging-mt_JFPafSWOWF

## Ready when they can

- Order the log write, the commit record and the page write, and say why
- Walk through redo and undo for a log that ends mid-transaction
- Explain what a checkpoint saves during recovery

## Lesson: Log first, so crashes lose nothing promised

Durability is achieved by writing the intention to a log before touching the data pages. The order is strict: the log record first, then the change to the page, and the commit record only after every change of the transaction sits safely in the log. A commit can be trusted the moment it returns, because everything promised is already in the log.

**Example.** Picture a log with two transactions: one finished with a commit record, one cut off mid stream with none. Recovery replays the committed work step by step until the pages match what was promised, which is called redo. The unfinished work gets rolled back and its partial changes removed, which is called undo. When recovery ends, every committed transaction is present and no unfinished one left a trace.

The log goes first because pages can be lost in a crash while the log survives on safe storage. If the intention is in the log, the work can be rebuilt. If it is not in the log, the work never happened, and nothing is owed to anyone.

**Tip.** Replaying a huge log takes time, so the system takes checkpoints. At a checkpoint it writes all pending changes into the data pages and notes the spot in the log. Recovery then starts from the last checkpoint instead of from the beginning, replaying only what came after.

**Recap.** Write the log before the pages, redo the committed, undo the rest, and checkpoint so recovery starts late.

## Practice

8 questions on this page, each with its working shown.

## Needs first

- [Concurrency Control: Locks and Snapshots](https://lightmysky.com/learn/computing/concurrency-control-locks-and-snapshots-mt_gOd17LRKel)
- [Crash Consistency and the Journal](https://lightmysky.com/learn/computing/crash-consistency-and-the-journal-mt_I9DT0TUmiu)

## Opens up

- [Failure Models and Replication](https://lightmysky.com/learn/computing/failure-models-and-replication-mt_aYK210-NIS)
- [Distributed Transactions and the Blocking Case of Two-Phase Commit](https://lightmysky.com/learn/computing/distributed-transactions-and-the-blocking-case-of-two-phase-commit-mt_MP_B_a_EwW)
- [Key-Value and Document Stores](https://lightmysky.com/learn/computing/key-value-and-document-stores-mt_PfBDSgfeQX)
