Goal
You see I/O spikes every few minutes, replicas that fall behind during batch loads, and a WAL archive that grows faster than the data. These are often the same problem: checkpoints run too often, and each one triggers a burst of full-page images (FPIs).
After the first change to a page following each checkpoint, PostgreSQL writes the whole 8 kB page into WAL (full_page_writes = on). More checkpoints mean more "first changes", so more FPIs, more WAL bytes, more archive traffic and more replica apply work. This post shows how to measure that and tune it.
Step 1: measure checkpoint frequency and cause
Checkpoints happen either on a timer (checkpoint_timeout) or when WAL since the last checkpoint approaches max_wal_size ("requested"). You want almost all of them to be timed.
PostgreSQL 17 and later:
SELECT num_timed, num_requested,
round(100.0 * num_requested / nullif(num_timed + num_requested, 0), 1) AS pct_requested,
write_time, sync_time, buffers_written, stats_reset
FROM pg_stat_checkpointer;
PostgreSQL 14 to 16 (the same counters lived in pg_stat_bgwriter):
SELECT checkpoints_timed, checkpoints_req,
checkpoint_write_time, checkpoint_sync_time, buffers_checkpoint, stats_reset
FROM pg_stat_bgwriter;
Turn on checkpoint logging. It's the default from PostgreSQL 15.
ALTER SYSTEM SET log_checkpoints = on;
SELECT pg_reload_conf();
Each log line gives the trigger, buffers written, write and sync times, and distance/estimate in kB. Messages like checkpoints are occurring too frequently (N seconds apart) come from checkpoint_warning (default 30s). They mean max_wal_size is too small for the write rate.
Tip
Reset statistics before a representative window (
SELECT pg_stat_reset_shared('checkpointer');on 17+, or'bgwriter'on older versions), so the ratios reflect today's workload rather than months of history.
Step 2: measure WAL volume and the FPI share
SELECT wal_records, wal_fpi, pg_size_pretty(wal_bytes) AS wal_bytes,
round(100.0 * wal_fpi / nullif(wal_records, 0), 1) AS pct_records_fpi,
wal_buffers_full, stats_reset
FROM pg_stat_wal;
wal_fpi counts records, not bytes. For a byte-level view, run pg_waldump --stats on a segment range from a busy period:
pg_waldump --stats=record -p "$PGDATA/pg_wal" 0000000100000A2B00000010 0000000100000A2B00000040
Look at the FPI size column against Record size. On update-heavy OLTP with short checkpoint intervals, FPIs commonly make up most of the WAL bytes.
You can also get the WAL rate per minute from two LSN samples:
SELECT pg_current_wal_lsn(); -- run, wait 60 s, run again
SELECT pg_size_pretty(pg_wal_lsn_diff('A2B/4F000000', 'A2B/40000000'));
Step 3: size max_wal_size from the write rate
Choose a checkpoint interval first, then size max_wal_size so that the timer, not the WAL volume, triggers checkpoints.
| Setting | What it controls | Starting point |
|---|---|---|
checkpoint_timeout | Maximum time between checkpoints | 15–30 min on busy OLTP. The default is 5 min |
max_wal_size | Soft WAL limit that forces a requested checkpoint | Peak WAL per checkpoint interval × ~1.5–2 |
checkpoint_completion_target | Fraction of the interval used to spread writes | 0.9 (the default from PG 14) |
min_wal_size | Recycled segments kept for bursts | Enough to absorb a normal burst without allocating new files |
Example: peak WAL is 600 MB per minute and you want 15-minute checkpoints. That's about 9 GB per interval, so max_wal_size should be around 16 GB.
ALTER SYSTEM SET checkpoint_timeout = '15min';
ALTER SYSTEM SET max_wal_size = '16GB';
ALTER SYSTEM SET min_wal_size = '4GB';
SELECT pg_reload_conf();
All four are reloadable, so no restart is needed. On managed services, set them in the parameter group or server parameters. Some services cap the values or manage them differently (Aurora doesn't use local WAL checkpoints in the same way), so check your service's documentation.
Warning
Longer checkpoint intervals mean longer crash recovery, because replay starts from the last checkpoint.
pg_walalso needs room formax_wal_sizeplus anything held by replication slots and archiving. Check disk headroom before you raise the value, and test crash recovery time on a copy if your RTO is tight.
Step 4: compress full-page images
wal_compression compresses FPIs only, not ordinary records. From PostgreSQL 15 it takes pglz, lz4 or zstd, provided the server was built with that library. Older versions accept only on/off (pglz).
SHOW wal_compression;
ALTER SYSTEM SET wal_compression = 'lz4'; -- PG 15+, if built with lz4
SELECT pg_reload_conf();
The trade-off is a little CPU on the primary for compression and on replicas for decompression, against fewer WAL bytes to write, ship, archive and apply. lz4 is the usual choice for low CPU cost. Measure wal_bytes per hour before and after.
Caution
Don't set
full_page_writes = offto save WAL unless your storage guarantees atomic 8 kB writes and you have proof of it. Without FPIs, a torn page after a crash can't be repaired from WAL, and that is silent corruption.
Step 5: check the background writer and checkpoint I/O
If checkpoints are now timed but still cause latency spikes:
- In the log lines, compare
write=againstsync=. A largesynctime points at the storage flush (for example, a cloud disk throughput cap), not at PostgreSQL settings. - Look at
buffers_writtenper checkpoint. If each checkpoint writes a large share ofshared_buffers, spreading the writes (checkpoint_completion_target) matters more than the interval. - On Linux,
checkpoint_flush_after(default 256 kB) limits how much dirty data the kernel holds before writeback. Leave it at the default unless you've measured a problem.
What to expect
| Symptom before | Likely cause | Change |
|---|---|---|
High num_requested | max_wal_size too small | Size it from the WAL rate (step 3) |
| Large FPI share of WAL bytes | Frequent checkpoints, many random updates | Longer interval plus wal_compression |
| Replica lag during batch jobs | WAL volume burst, mostly FPIs | Same as above, then tune replica apply |
Spikes with long sync= times | Storage flush limits | Faster disk tier or more provisioned throughput |
wal_buffers_full rising fast | wal_buffers too small for bursts | Raise wal_buffers (needs a restart) |
Prevent it next time
- Chart WAL bytes per hour, requested-checkpoint percentage and FPI share next to your replica lag. When the requested share rises, that's an early warning that write volume has outgrown
max_wal_size. - Re-check sizing after any change in workload: new batch jobs, bulk loads, or index additions on hot tables.
- Keep checkpoint settings in the same configuration-as-code as the rest of
postgresql.conf, with the measured WAL rate noted in the commit message.
Get the weekly HubDatAI email
One email a week with everything new: posts, learning sessions and videos. Free, no spam, unsubscribe in one click. What you get