DB Internals AtlasPostgreSQL 18.6 Home About

Parameter · Replication / Sending Servers

wal_keep_size

Sets the size of WAL files held for standby servers.

  • Default: 0
  • Type: integer (MB)
  • Range: 0 … max (2147483647)
  • Applies: Reload

In plain words

A standby without a replication slot can fall behind. If the primary has already recycled the WAL the standby still needs, the standby cannot continue and has to be rebuilt. wal_keep_size tells the primary to always keep at least this much recent WAL around, as a safety margin.

The default 0 keeps nothing extra. A slot is the precise solution; this is the simple, bounded one.

For DBAs and operators

Checkpoints normally remove or recycle WAL segments older than the last checkpoint's redo point. With wal_keep_size set, the most recent N MB of segments are never removed, regardless of whether any standby needs them. It is a minimum: slots, archiving and max_wal_size can keep more. It replaced wal_keep_segments in PostgreSQL 13 (old value × 16 MB).

When a standby asks for a removed segment, the primary's walsender reports it and the standby logs:

FATAL: could not receive data from WAL stream: ERROR: requested WAL segment 000000010000000000000042 has already been removed

A standby with a working restore_command can still catch up from the archive; otherwise re-clone it.

Sizing

Measure WAL generation per hour (pg_stat_wal.wal_bytes or LSN differences) and multiply by the longest outage you want to survive. The space is always used, even when all standbys are current. Prefer slots plus max_slot_wal_keep_size for exact retention with a safety cap.

How to change it

Change in postgresql.conf or ALTER SYSTEM, then run SELECT pg_reload_conf().

See it in context

Streaming replication Replication slots Write-ahead log (WAL) Checkpointer Archiver WAL sender

Related parameters

max_slot_wal_keep_size primary_slot_name max_wal_size wal_receiver_create_temp_slot

All Replication parameters