Use it when the WAL directory grows, checkpoints are too frequent, or for PITR setup.
WAL and Checkpoints
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.
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.
change → WAL record → flushed → checkpoint → WAL archived/recycled
Context & applicabilityCommon mistakes · platform/version boundaries
Operational reference
Fast context before you go deeper.
Verification & Troubleshooting
Start with the observed symptom, prove the nearest boundary, and move outward only when the current state is understood.
Use the operational verification above to establish the expected state.
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
| Setting | Purpose |
|---|---|
wal_level | replica for replication/PITR, logical for logical replication |
max_wal_size | Checkpoint spacing; too small → frequent checkpoints |
checkpoint_timeout | Time between checkpoints |
archive_mode / archive_command | Copy 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.
WAL grows when archiving fails, a replication slot is inactive, or max_wal_size is reached frequently. Inactive replication slots can fill the disk.
SELECT pg_size_pretty(sum(size)) FROM pg_ls_waldir();— first check for this topicpsql -c "SELECT now(), version();"— PostgreSQL reachable and versionmysql -e "SELECT NOW(), VERSION();"— MariaDB/MySQL reachable and versionsqlcmd -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 often | Checkpoints less often |
|---|---|
| Faster crash recovery | Longer 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 bursts | Smoother 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
| Cause | Check |
|---|---|
| Inactive replication slot | SELECT slot_name, active, wal_status, safe_wal_size FROM pg_replication_slots; |
| Failing archive | SELECT failed_count, last_failed_wal, last_failed_time FROM pg_stat_archiver; |
Large wal_keep_size | SHOW 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.
Common mistakes
max_wal_sizetoo small, causing frequent checkpoints.
Additional reference context Scope · expected state · examples · history · terminology Open only when you need the supporting context
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.