Skip to content

WAL & Archive Mode

Problem

  • Set wal_keep_size
  • Set archive_mode=on
  • Unset archive_command

This will cause wal_keep_size to not work and the disk to fill up.

wal_keep_size

  • Controls the minimum number of WAL files that PostgreSQL will retain, even if they have been used by streaming replication clients or archive processing.
  • It is a soft limit. For example, if set to 1GB, PostgreSQL will try to keep approximately 1GB of WAL files (in bytes) to avoid deletion, which is particularly useful for streaming replication clients.

archive_mode=on

  • Indicates that WAL archiving is enabled.
  • You also need to set archive_command, for example:
bash
archive_command = 'cp %p /var/lib/postgresql/wal_archive/%f'

This means that when a WAL is completed, it will be copied to the archive directory.

Behavior When Configured Together

  • archive_mode = on + archive_command will archive WAL files to your specified location, and they won't be deleted until archiving is successful.
  • wal_keep_size will retain a portion of WAL files in the main directory for streaming replication and other uses.
  • If a WAL file hasn't been archived yet, PostgreSQL will keep it (even if it exceeds the wal_keep_size limit) — archiving has higher priority.