wal_keep_segments
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
.
Usage
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
- PostgreSQL 13
- renamed to
wal_keep_size
(commit f5dff459)
- renamed to
- PostgreSQL 9.0
- added, initially as
standby_keep_segments
(initial commit e57cd7f0)
- added, initially as
References
- PostgreSQL 12 documentation: wal_keep_segments