Pcornel
Databases · PostgreSQL

WAL and Checkpoints

Cheat sheet · https://pcornel.dk/topic.php?topic=6181

Back to the Topic

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.

Remember

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

First 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

Commands

SHOW wal_keep_size;

Verify in this order

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

Where it usually breaks

An inactive replication slot retains WAL until the disk fills.

Read-only verification commands unless stated otherwise. Confirm syntax for your platform and release. Full reference: https://pcornel.dk/topic.php?topic=6181

Confirmation

Confirm action

Continue?