Transactions and Recovery Theory

What are checkpoints in a database management system (DBMS)?

A checkpoint is a point where a DBMS flushes modified data to disk and logs a marker. Learn how checkpoints speed up recovery, and why they aren't backups.

On this page
  1. Why checkpoints are needed
  2. What happens during a checkpoint
  3. How recovery uses a checkpoint
  4. Checkpoint types in SQL Server
  5. The trade-off
  6. Checkpoints are not backups
  7. Where checkpoints fit
  8. Summary

A checkpoint is a point during normal operation where the DBMS writes modified data from memory to disk and records a checkpoint marker in the transaction log. After a crash, recovery can start from the last checkpoint instead of the beginning of the log, which makes restarting faster.

Why checkpoints are needed

To stay fast, a DBMS keeps changed data in memory and writes it to disk later. The transaction log records every change, so the database can be rebuilt after a crash. Without checkpoints, recovery might have to read a long stretch of the log and replay work that was already safely on disk. A long log means a long wait before the database is available again.

What happens during a checkpoint

Each system does this differently, but the textbook version has three steps:

  1. Write the log records still held in memory to stable storage.
  2. Write the modified data in memory to disk.
  3. Write a checkpoint record to the log. It lists the transactions that were still active at that moment.

Simple checkpoint schemes may pause updates while they run. Some systems use fuzzy checkpoints, which let normal work continue while the checkpoint runs.

How recovery uses a checkpoint

After a crash, recovery reads the log backward to find the most recent checkpoint record. It then needs to look only at transactions that were active at that checkpoint and transactions that started after it. Committed work from that point is redone. Unfinished work may need to be undone, a step covered in What is immediate database modification and how does it work?

A long-running transaction can make recovery slower, because it may have to be undone from far back in the log. Microsoft’s SQL Server documentation makes a similar point: long-running, uncommitted transactions increase recovery time for all checkpoint types.

Checkpoint types in SQL Server

SQL Server describes four kinds of checkpoints:

  • Automatic checkpoints run in the background to meet the time limit set by the server’s recovery interval option.
  • Indirect checkpoints aim for a target recovery time that is set per database.
  • Manual checkpoints run when someone issues the CHECKPOINT command.
  • Internal checkpoints happen during operations such as backups.

The trade-off

Checkpoints involve a balance:

  • Frequent checkpoints shorten recovery, but they add disk writes during normal work.
  • Infrequent checkpoints reduce that load, but they leave more of the log to replay after a crash.

Checkpoints are not backups

Recovery replays committed work. A committed DELETE is part of that work, so a checkpoint does not bring deleted rows back. Recovering from a mistake like that takes other tools, such as a backup. For SQL Server, the options are covered in How to Recover Deleted Data From a SQL Server Database.

Where checkpoints fit

Checkpoints are one part of the recovery process covered in deferred and immediate database modification. How a checkpoint is used depends on the log and on how the DBMS handles changes that were not committed when the checkpoint ran.

Summary

  • A checkpoint writes modified data to disk and records a marker in the log.
  • Recovery can start from the last checkpoint, which shortens the time needed to restart.
  • Checkpoints are not backups. Committed changes, including deletes, are replayed during recovery.

The complete guide to transactions and recovery theory

Deferred and Immediate Database Modification Explained
Read the guide

Keep exploring

Guides from other topics

All topics →