Pcornel
Browse topics
Options
Recent
Favorites
Databases · Technical reference

WAL and Checkpoints

Direct answer

PostgreSQL writes every change to the WAL before data files; checkpoints flush dirty pages so WAL can be recycled. WAL also feeds replication and PITR.

When to use this

Use it when the WAL directory grows, checkpoints are too frequent, or for PITR setup.

First 30 seconds

1. WAL size: SELECT pg_size_pretty(sum(size)) FROM pg_ls_waldir();.

2. Archiving: SELECT * FROM pg_stat_archiver; — failures?

3. Slots: SELECT slot_name,active,restart_lsn FROM pg_replication_slots;.

4. Checkpoint warnings in log.

5. Fix archive/slot; tune max_wal_size.

Operational verification

change → WAL record → flushed → checkpoint → WAL archived/recycled

Context & applicabilityCommon mistakes · platform/version boundaries
Platform / version applicability
MariaDB / MySQL / PostgreSQL / Microsoft SQL Server concepts
applies
Structured applicability is explicit Topic metadata; it does not infer compatibility beyond the stored rows.
At a glance

Operational reference

Fast context before you go deeper.

PlatformMariaDB / MySQL / PostgreSQL / Microsoft SQL Server concepts
Scope / prerequisiteUse it when the WAL directory grows, checkpoints are too frequent, or for PITR setup.
What next?2 suggested next steps
Evidence0
On this pageJump to a specific section
Operational workflow

Verification & Troubleshooting

Start with the observed symptom, prove the nearest boundary, and move outward only when the current state is understood.

3 steps Observe → verify → isolate → change minimally → repeat the original test.
ObservedRecord what the original test actually shows

Capture the concrete output, symptom, packet, log or counter before changing anything.

Step 1 How to verify Verify boundary

Look at the log for "checkpoints are occurring too frequently". Monitor pg_wal size and inactive replication slots.

Step 2 Key settings and checks Verify boundary
SettingPurpose
wal_levelreplica for replication/PITR, logical for logical replication
max_wal_sizeCheckpoint spacing; too small → frequent checkpoints
checkpoint_timeoutTime between checkpoints
archive_mode / archive_commandCopy WAL for PITR
SELECT * FROM pg_stat_checkpointer;      -- PG 17 (pg_stat_bgwriter earlier)
SELECT slot_name, active, pg_size_pretty(pg_wal_lsn_diff(pg_current_wal_lsn(), restart_lsn)) FROM pg_replication_slots;

Inactive replication slots retain WAL until the disk is full — monitor them.

Step 3 Common failures Narrow the fault

An inactive replication slot retains WAL until the disk fills. Failed archive_command also retains WAL. Very large max_wal_size makes crash recovery longer.

Key points

WAL grows when archiving fails, a replication slot is inactive, or max_wal_size is reached frequently. Inactive replication slots can fill the disk.

Key checks
  • SELECT pg_size_pretty(sum(size)) FROM pg_ls_waldir(); — first check for this topic
  • psql -c "SELECT now(), version();" — PostgreSQL reachable and version
  • mysql -e "SELECT NOW(), VERSION();" — MariaDB/MySQL reachable and version
  • sqlcmd -S <server> -Q "SELECT @@VERSION" — SQL Server reachable and version
ReferenceWhat it is1 section · depth on demand

How it works

Checkpoints happen on a timer (checkpoint_timeout) or when WAL reaches max_wal_size. Frequent requested checkpoints mean max_wal_size is too small. Archiving copies WAL segments for point-in-time recovery.

ReferenceImportant terms & boundaries2 sections · depth on demand

In depth

What a checkpoint does

At a checkpoint all dirty pages are written to the data files and a checkpoint record is written to WAL; crash recovery then starts from that point. WAL before the last checkpoint is no longer needed for crash recovery (but may still be kept for archiving, slots or wal_keep_size).

The balance

Checkpoints more oftenCheckpoints less often
Faster crash recoveryLonger crash recovery
More full-page writes (first change of each page after a checkpoint writes the whole page to WAL)Less WAL volume
More I/O burstsSmoother I/O with checkpoint_completion_target = 0.9

Diagnosing frequent checkpoints

-- PostgreSQL 17+: checkpoint counters moved to pg_stat_checkpointer
SELECT num_timed, num_requested FROM pg_stat_checkpointer;

Requested checkpoints are triggered by WAL reaching max_wal_size. If they dominate timed ones during normal load, raise max_wal_size until most checkpoints are timed (checkpoint_timeout, default 5 min; many systems use 15 min). The log also says checkpoints are occurring too frequently when checkpoint_warning is exceeded.

Why pg_wal grows

CauseCheck
Inactive replication slotSELECT slot_name, active, wal_status, safe_wal_size FROM pg_replication_slots;
Failing archiveSELECT failed_count, last_failed_wal, last_failed_time FROM pg_stat_archiver;
Large wal_keep_sizeSHOW wal_keep_size;

Set max_slot_wal_keep_size so a forgotten slot is invalidated instead of filling the disk. Never delete files in pg_wal by hand.

Source basisSource attribution states what this section is based on; it is not independent proof that the current environment matches it.

Common mistakes

  • max_wal_size too small, causing frequent checkpoints.
Additional reference context Scope · expected state · examples · history · terminology Open only when you need the supporting context
Terminology layer

Terms & aliases

Hover a linked term for a quick definition; click it to open its glossary entry. Aliases are other names that find this Topic in search.

Aliases that resolve here
wal and checkpointspostgresql walreplication slot disk full
Confirmation

Confirm action

Continue?