A server parameter determining the minimum number of WAL files to retain
This entry relates to a PostgreSQL feature which is deprecated and may be desupported in future releases.

wal_keep_segments is a configuration parameter determining the minimum number of WAL files to retain in the pg_wal directory.

wal_keep_segments was added in PostgreSQL 9.0 and renamed in PostgreSQL 13 to wal_keep_size.

Default value

The default value for wal_keep_segments is: 0.


By setting wal_keep_segments to a value greater than zero, it's possible to force PostgreSQL to maintain a minimum amount of WAL files on the local server. This can be useful when e.g. executing pg_basebackup to create a copy of the server to ensure that changes made since the start of the backup can be fetched after the backup has completed, or to try and prevent a situation where if a standby is unable to connect to the primary or upstream node, it can still retrieve a sufficient amount of WAL to catch up.

However this is not a reliable method of WAL retention as it is difficult or even impossible to set a value sufficiently high enough to cover all possible cases where WAL might need to be retrieved, without running the risk of exhausting storage space on the local server. A more reliable solution usually involves replication slots and a WAL archive.

Change history


Deprecated, GUC configuration item, WAL

See also

wal_keep_size, max_wal_size, min_wal_size