// postgresql · wal, redo & durability

wal_keep_size

WAL held back in pg_wal so a streaming standby that reconnects can catch up.

默认
0
Range
0 to about 2PB, in MB
Restart needed
否
Default checked on
PostgreSQL 18

作用

The minimum size of past WAL segments reserved for standby servers. A standby that disconnects briefly re-reads what it missed; segments already recycled force a fresh base backup. Renamed from wal_keep_segments in PostgreSQL 13, which counted 16MB segments rather than megabytes.

默认值

0. 0 (PostgreSQL 18); exists as wal_keep_size since PostgreSQL 13 (wal_keep_segments before).

Check the current value

SHOW wal_keep_size;

SELECT setting, unit, boot_val, context, source, pending_restart
FROM pg_settings
WHERE name = 'wal_keep_size';

Change it

ALTER SYSTEM SET wal_keep_size = '1GB';
SELECT pg_reload_conf();

No restart: reload with SELECT pg_reload_conf() or pg_ctl reload. It cannot be changed per session (context is sighup).

When to change it

On primaries with physical standbys that do not use replication slots, or as extra margin next to a slot sized by max_slot_wal_keep_size.

What can go wrong

The space is held in pg_wal even when no standby is connected, so a value far above what the standbys need is wasted disk. A standby that falls further behind than this plus any slot allowance cannot rejoin without a base backup.

Questions about wal_keep_size

What is the default value of wal_keep_size in PostgreSQL?

0. 0 (PostgreSQL 18); exists as wal_keep_size since PostgreSQL 13 (wal_keep_segments before).

Does changing wal_keep_size require a restart?

No. No restart: reload with SELECT pg_reload_conf() or pg_ctl reload. It cannot be changed per session (context is sighup).

When should I change wal_keep_size?

On primaries with physical standbys that do not use replication slots, or as extra margin next to a slot sized by max_slot_wal_keep_size.

Back to all PostgreSQL settings, or check the PostgreSQL manual for every option.

// one client for every engine

Check wal_keep_size on your own server

SQLly runs the query above against PostgreSQL and the other engines in this reference, from one desktop app on macOS, Windows and Linux.

本页文字和数据: CC BY 4.0,请注明出处 SQLly (sqlly.app)。 代码和 SQL 片段: MIT. 许可详情