PostgreSQL

PostgreSQL WAL Configuration: fsync, synchronous_commit, and Checkpoint Tuning

Tune PostgreSQL WAL for durability and performance. Covers synchronous_commit tradeoffs, checkpoint frequency monitoring, WAL archiving, and full_page_writes safety.

JusDB Team
October 16, 2025
5 min read
153 views

WAL (Write-Ahead Log) configuration affects PostgreSQL durability, performance, and replication. Getting it wrong means either data loss risk or unnecessary I/O overhead.

Key WAL Parameters

ini
# postgresql.conf
wal_level = replica          # minimal, replica, or logical
fsync = on                   # NEVER disable in production
synchronous_commit = on      # on, remote_write, remote_apply, local, off
wal_buffers = 64MB           # default -1 (auto ~3% of shared_buffers)
wal_writer_delay = 200ms     # how often wal writer flushes
checkpoint_timeout = 15min   # max time between checkpoints
max_wal_size = 2GB           # trigger checkpoint when WAL exceeds this
min_wal_size = 80MB

synchronous_commit Tradeoffs

text
Setting         Data Loss Risk    Write Latency
----------------|-----------------|-------------
on (default)    None              Higher
remote_apply    None (with HA)    Highest
local           On standby only  Medium
off             Up to 3×wal_writer_delay  Lowest
sql
-- Per-transaction override (e.g., for non-critical writes)
SET LOCAL synchronous_commit = off;
INSERT INTO audit_log (event) VALUES ('page_view');
COMMIT;

Monitor Checkpoint Frequency

sql
SELECT checkpoints_timed, checkpoints_req,
       checkpoint_write_time, checkpoint_sync_time,
       buffers_checkpoint, buffers_clean
FROM pg_stat_bgwriter;

-- checkpoints_req >> checkpoints_timed means max_wal_size is too small
-- Increase max_wal_size to reduce I/O spikes from forced checkpoints

WAL Archiving

ini
archive_mode = on
archive_command = 'wal-g wal-push %p'
archive_timeout = 300   # force archive at least every 5 minutes

full_page_writes

ini
full_page_writes = on  # NEVER disable — prevents partial page write corruption
# After a checkpoint, first write to any page includes full page image in WAL
# Required for crash safety

Key Takeaways

  • Never disable fsync or full_page_writes — these prevent data corruption
  • If checkpoints_req is high, increase max_wal_size to reduce I/O spikes
  • Use synchronous_commit = off per-transaction for non-critical writes to reduce latency
  • Set archive_timeout to limit RPO exposure when WAL archiving to S3

JusDB Can Help

WAL misconfiguration is a common cause of both performance problems and data loss. JusDB can review your WAL configuration and tune it for your durability requirements.

Share this article

JusDB Team

Official JusDB content team