{"Entry":{"collection":"guc","key":"wal_keep_segments","name":"wal_keep_segments","aliases":[],"metadata":{"baseline":false,"boot_human":"0","boot_val":"0","category":"Replication / Sending Servers","category_zh":"","changed_in":["9.1","9.2"],"changes":[{"documentation_changed":false,"fields":{},"from":"8.4","status":"added","to":"9.0"},{"documentation_changed":true,"fields":{"category":{"from":"Write-Ahead Log / Streaming Replication","to":"Replication / Master Server"}},"from":"9.0","status":"changed","to":"9.1"},{"documentation_changed":true,"fields":{"category":{"from":"Replication / Master Server","to":"Replication / Sending Servers"}},"from":"9.1","status":"changed","to":"9.2"},{"documentation_changed":true,"fields":{},"from":"9.6","status":"changed","to":"10"},{"documentation_changed":false,"fields":{},"from":"12","status":"removed","to":"13"}],"content_hash":"65f4827bbb6d7ea1f939ae506b4656f9baa08812514b93f41adfeeb996005a38","context":"sighup","default_changed_in":[],"default_history":[{"from":"9.0","to":"12","value":"0"}],"editorial":{"advice":{"olap":"Use the same migration path as OLTP, and also verify long batches, standbys, or large-object/extension workflows; removal of the old switch does not promise identical legacy behavior.","oltp":"Do not tune or continue emitting wal_keep_segments on PG13+. PostgreSQL 13 replaced the segment-count interface with wal_keep_size, which expresses the retention floor in bytes rather than assuming a segment size. Scan every configuration layer and regression-test the application before upgrade.","small":"Delete the obsolete setting and adopt the supported replacement directly; do not emulate legacy behavior in scripts without a demonstrated compatibility requirement."},"mechanism":["Sets the number of WAL files held for standby servers. The parameter still exists in PG12 and is no longer recognized from PG13. PostgreSQL 13 replaced the segment-count interface with wal_keep_size, which expresses the retention floor in bytes rather than assuming a segment size.","This retained at least a count of old WAL segments for lagging standbys, so its byte effect changed with wal_segment_size. It was only a floor—not protection from every retention/removal condition—and PostgreSQL 13 replaced it with wal_keep_size.","Before upgrading, inspect wal_keep_size, wal_segment_size, max_slot_wal_keep_size, remove the old name from configuration, ALTER SYSTEM, role/database settings, and automation templates, and verify the replacement before starting PG13 or later."],"pitfalls":["Copying the old integer directly to wal_keep_size without multiplying by wal_segment_size.","Treating the retained count as a maximum rather than a minimum floor.","Leaving the removed name in PG13+ automation.","Continuing to emit unknown parameter wal_keep_segments on PG13+.","Deleting only the setting name without migrating dependent application behavior."],"references":[{"title":"PostgreSQL 12: wal_keep_segments","url":"https://www.postgresql.org/docs/12/runtime-config-replication.html#GUC-WAL-KEEP-SEGMENTS"}],"related":["wal_keep_size","wal_segment_size","max_slot_wal_keep_size","max_wal_size","primary_slot_name","idle_replication_slot_timeout"],"summary":"wal_keep_segments — Sets the number of WAL files held for standby servers. Observed in PG9.0–12; its last measured boot default is 0 in PG12, with sighup context. It was removed in PG13."},"enumvals":[],"first_version":"9.0","group":"Replication","group_slug":"replication","imported_at":"2026-09-27T17:57:32.333768+08:00","intro_commit":{},"key":"wal_keep_segments","last_version":"12","max_val":"2147483647","min_val":"0","name":"wal_keep_segments","position":469,"present_in":["9.0","9.1","9.2","9.3","9.4","9.5","9.6","10","11","12"],"short_desc":"Specifies the minimum number of past log file segments kept in the pg_wal directory, in case a standby server needs to fetch them for streaming replication.","short_desc_zh":"","source_rev":"english-manuals:28aaca6451f31d706ed4336331796f5031f4a72cedaaf457a4d788d8e5214049","unit":"","vartype":"integer"}},"Definition":{"Collection":"guc","Key":"wal_keep_segments","SourceDatabase":"center","Version":"12","SourceTable":"guc","SourceKey":"wal_keep_segments","SourceRevision":"english-manuals:28aaca6451f31d706ed4336331796f5031f4a72cedaaf457a4d788d8e5214049","Facts":{"boot_val":"0","category":"Replication / Sending Servers","context":"sighup","description":"Specifies the minimum number of past log file segments kept in the pg_wal directory, in case a standby server needs to fetch them for streaming replication. Each segment is normally 16 megabytes. If a standby server connected to the sending server falls behind by more than wal_keep_segments segments, the sending server might remove a WAL segment still needed by the standby, in which case the replication connection will be terminated. Downstream connections will also eventually fail as a result. (However, the standby server can recover by fetching the segment from archive, if WAL archiving is in use.) This sets only the minimum number of segments retained in pg_wal; the system might need to retain more segments for WAL archival or to recover from a checkpoint. If wal_keep_segments is zero (the default), the system doesn't keep any extra segments for standby purposes, so the number of old WAL segments available to standby servers is a function of the location of the previous checkpoint and status of WAL archiving. This parameter can only be set in the postgresql.conf file or on the server command line.","doc":{"anchor":"GUC-WAL-KEEP-SEGMENTS","file":"runtime-config-replication.html","lang":"en","sha256":"983574942b54db68cc363f26190e6015c501adbeb02fcb5ef998f7d914deb764","slug":"12"},"documented":true,"enumvals":null,"extra_desc":null,"lang":"en","max_val":"2147483647","metadata_version":"12","min_val":"0","name":"wal_keep_segments","short_desc":"Sets the number of WAL files held for standby servers.","source":"pg-settings-source-snapshot","unit":null,"vartype":"integer"},"ManualEvidence":{"doc":{"anchor":"GUC-WAL-KEEP-SEGMENTS","file":"runtime-config-replication.html","lang":"en","sha256":"983574942b54db68cc363f26190e6015c501adbeb02fcb5ef998f7d914deb764","slug":"12"}},"MeasuredEvidence":{"metadata_version":"12"}},"Text":{"Collection":"guc","Key":"wal_keep_segments","SourceDatabase":"center","Version":"12","Locale":"en","Title":"wal_keep_segments","Summary":"Specifies the minimum number of past log file segments kept in the pg_wal directory, in case a standby server needs to fetch them for streaming replication. Each segment is normally 16 megabytes. If a standby server connected to the sending server falls behind by more than wal_keep_segments segments, the sending server might remove a WAL segment still needed by the standby, in which case the replication connection will be terminated. Downstream connections will also eventually fail as a result. (However, the standby server can recover by fetching the segment from archive, if WAL archiving is in use.) This sets only the minimum number of segments retained in pg_wal; the system might need to retain more segments for WAL archival or to recover from a checkpoint. If wal_keep_segments is zero (the default), the system doesn't keep any extra segments for standby purposes, so the number of old WAL segments available to standby servers is a function of the location of the previous checkpoint and status of WAL archiving. This parameter can only be set in the postgresql.conf file or on the server command line.","BodyHTML":"\u003cp\u003eSpecifies the minimum number of past log file segments kept in the pg_wal directory, in case a standby server needs to fetch them for streaming replication. Each segment is normally 16 megabytes. If a standby server connected to the sending server falls behind by more than wal_keep_segments segments, the sending server might remove a WAL segment still needed by the standby, in which case the replication connection will be terminated. Downstream connections will also eventually fail as a result. (However, the standby server can recover by fetching the segment from archive, if WAL archiving is in use.) This sets only the minimum number of segments retained in pg_wal; the system might need to retain more segments for WAL archival or to recover from a checkpoint. If wal_keep_segments is zero (the default), the system doesn\u0026#39;t keep any extra segments for standby purposes, so the number of old WAL segments available to standby servers is a function of the location of the previous checkpoint and status of WAL archiving. This parameter can only be set in the postgresql.conf file or on the server command line.\u003c/p\u003e","SourceRevision":"english-manuals:28aaca6451f31d706ed4336331796f5031f4a72cedaaf457a4d788d8e5214049","ContentHash":"deb29ad5a0f3cbf3c02698fdef0d6f745243e9ccae234de08e9ae7c7b5b4045a","Payload":{"description":"Specifies the minimum number of past log file segments kept in the pg_wal directory, in case a standby server needs to fetch them for streaming replication. Each segment is normally 16 megabytes. If a standby server connected to the sending server falls behind by more than wal_keep_segments segments, the sending server might remove a WAL segment still needed by the standby, in which case the replication connection will be terminated. Downstream connections will also eventually fail as a result. (However, the standby server can recover by fetching the segment from archive, if WAL archiving is in use.) This sets only the minimum number of segments retained in pg_wal; the system might need to retain more segments for WAL archival or to recover from a checkpoint. If wal_keep_segments is zero (the default), the system doesn't keep any extra segments for standby purposes, so the number of old WAL segments available to standby servers is a function of the location of the previous checkpoint and status of WAL archiving. This parameter can only be set in the postgresql.conf file or on the server command line."}},"RequestedLocale":"zh-Hans","Fallback":true,"Versions":["10","11","12","9.0","9.1","9.2","9.3","9.4","9.5","9.6"],"Locales":["en"],"Signatures":null,"Spellings":null,"SQLState":null,"Evidence":null}
