{"Entry":{"collection":"guc","key":"wal_keep_size","name":"wal_keep_size","aliases":[],"metadata":{"baseline":false,"boot_human":"Not specified","boot_val":null,"category":"Replication / Sending Servers","category_zh":"","changed_in":[],"changes":[{"documentation_changed":false,"fields":{},"from":"12","status":"added","to":"13"},{"documentation_changed":true,"fields":{},"from":"15","status":"changed","to":"16"}],"content_hash":"d525e7b7d416503818f7c19e441c87c6c9e3e791d1337f08db49c45523e4d1b2","context":"","default_changed_in":[],"default_history":[{"from":"13","to":"19","value":"0 B"}],"derived_content_hash":"fe8f6dee79fefb6ff3e9363ab07237797692494a028766d1010fc6b21a0a0657","documentation_refresh":{"batch":"20261113","original_source_rev":"wiki-repair-20261023:ee15467e323664f70e3c58869241aa78cd5b322ae4abcc517e956f3c4fa8e04f","versions":{"14":"14.25","15":"15.20","16":"16.16","17":"17.12","18":"18.7","19":"19rc2"}},"editorial":{"advice":{"olap":"Static retention can be overwhelmed by a short bulk-load burst. Use slots or an archive for consumers that must survive such bursts, and size any wal_keep_size floor against peak rather than average WAL generation.","oltp":"Prefer monitored replication slots plus a tested archive for durable protection. If a nonzero floor is needed, calculate it from peak WAL bytes per second and tolerated disconnection time, then add margin and alert on replication lag.","small":"Leave it at 0 when slots and archive recovery are reliable. Otherwise choose a modest bounded floor that cannot consume the disk budget during an unrelated archive or slot incident."},"mechanism":["The sender keeps at least wal_keep_size megabytes of past WAL in pg_wal so a lagging standby can continue streaming without an older segment disappearing. If the standby falls behind beyond the available files, streaming disconnects; an archive can supply the missing segment if one exists.","This is a retention floor, not an exact reservation or a maximum. Checkpoint recovery needs, archiving, replication slots, and recent WAL-usage estimates can retain more. A value of zero means PostgreSQL reserves no extra WAL specifically for standbys, not that pg_wal contains no old WAL.","Replication slots retain WAL according to an individual consumer's confirmed position and are usually more precise. wal_keep_size is still useful as simple insurance for slotless or temporarily reconnecting standbys, but capacity should be based on peak WAL rate multiplied by the intended outage window."],"pitfalls":["Treating wal_keep_size as a maximum for pg_wal usage.","Reading 0 as 'retain no WAL' rather than 'retain no extra WAL for standby purposes'.","Sizing from average WAL rate and failing during batch-generated peaks.","Assuming it guarantees recovery after a standby exceeds the retained window.","Forgetting the predecessor parameter wal_keep_segments when comparing PG12 and PG13."],"references":[{"title":"PostgreSQL 19 Beta 4: wal_keep_size","url":"https://www.postgresql.org/docs/19/runtime-config-replication.html#GUC-WAL-KEEP-SIZE"},{"title":"PostgreSQL 18: Replication Slots","url":"https://www.postgresql.org/docs/18/warm-standby.html#STREAMING-REPLICATION-SLOTS"},{"title":"PostgreSQL 18: WAL Configuration","url":"https://www.postgresql.org/docs/18/wal-configuration.html"},{"title":"PostgreSQL 19 release notes","url":"https://www.postgresql.org/docs/19/release-19.html"}],"related":["wal_keep_segments","max_replication_slots","max_slot_wal_keep_size","archive_mode","max_wal_size","primary_slot_name"],"summary":"A reloadable minimum amount of old WAL retained for streaming standbys that might fall behind."},"enumvals":[],"first_version":"13","group":"Replication","group_slug":"replication","imported_at":"2026-09-27T17:57:32.336627+08:00","intro_commit":{"authored_at":"2020-07-20T13:30:18+09:00","discussion":["https://postgr.es/m/574b4ea3-e0f9-b175-ead2-ebea7faea855@oss.nttdata.com"],"hash":"f5dff45962ec0a0daad443e45811d6c426be1237","subject":"Rename wal_keep_segments to wal_keep_size.","url":"https://git.postgresql.org/gitweb/?p=postgresql.git;a=commit;h=f5dff45962ec0a0daad443e45811d6c426be1237"},"key":"wal_keep_size","last_version":"20","max_val":"","min_val":"","name":"wal_keep_size","position":470,"present_in":["13","14","15","16","17","18","19","20"],"repair_provenance":{"original_source_revision":"english-manuals:41ea768d960426aebf4831e4221c04bd02ed831b428f4ed44d640a093645ee33","receipt_sha256":"ddcbe68889160c8bbeb5a06101ead7341857118bd8b87e1003c1ed1cd0d130b2","repair":"wiki-repair-20261023"},"short_desc":"Specifies the minimum size of past WAL files kept in the pg_wal directory, in case a standby server needs to fetch them for streaming replication.","short_desc_zh":"","source_rev":"wiki-repair-20261023:ee15467e323664f70e3c58869241aa78cd5b322ae4abcc517e956f3c4fa8e04f","unit":"","vartype":"integer"}},"Definition":{"Collection":"guc","Key":"wal_keep_size","SourceDatabase":"center","Version":"18","SourceTable":"guc","SourceKey":"wal_keep_size","SourceRevision":"wiki-repair-20261023:ee15467e323664f70e3c58869241aa78cd5b322ae4abcc517e956f3c4fa8e04f","Facts":{"boot_val":"0","category":"Replication / Sending Servers","context":"sighup","description":"Specifies the minimum size of past WAL files kept in the pg_wal directory, in case a standby server needs to fetch them for streaming replication. If a standby server connected to the sending server falls behind by more than wal_keep_size megabytes, 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 size 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_size 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. If this value is specified without units, it is taken as megabytes. This parameter can only be set in the postgresql.conf file or on the server command line.","description_zh":"指定在 pg_wal 目录中保留的旧 WAL 文件的最小总量，以便备库需要时获取这些文件进行流复制。如果连接到发送服务器的备库落后超过 wal_keep_size 兆字节，发送服务器可能会移除备库仍需要的 WAL 段，从而导致复制连接终止。下游连接最终也会因此失败。（不过，如果使用了 WAL 归档，备库可以通过从归档获取该段来恢复。） 此设置只规定 pg_wal 中保留的段的最小总量；系统可能需要为 WAL 归档或从检查点恢复而保留更多段。如果 wal_keep_size 为零（默认值），系统不会为备库额外保留任何段，因此备库可用的旧 WAL 段数取决于前一个检查点的位置和 WAL 归档的状态。如果指定值时没有单位，则按兆字节计算。此参数只能在 postgresql.conf 文件中或服务器命令行上设置。","description_zh_html":"\u003cp\u003e\n        指定在 \u003ccode class=\"filename\"\u003epg_wal\u003c/code\u003e 目录中保留的旧 WAL 文件的最小总量，以便备库需要时获取这些文件进行流复制。如果连接到发送服务器的备库落后超过\n        \u003ccode class=\"varname\"\u003ewal_keep_size\u003c/code\u003e 兆字节，发送服务器可能会移除备库仍需要的 WAL 段，从而导致复制连接终止。下游连接最终也会因此失败。（不过，如果使用了 WAL 归档，备库可以通过从归档获取该段来恢复。）\n       \u003c/p\u003e\u003cp\u003e\n        此设置只规定 \u003ccode class=\"filename\"\u003epg_wal\u003c/code\u003e 中保留的段的最小总量；系统可能需要为 WAL 归档或从检查点恢复而保留更多段。如果 \u003ccode class=\"varname\"\u003ewal_keep_size\u003c/code\u003e 为零（默认值），系统不会为备库额外保留任何段，因此备库可用的旧 WAL 段数取决于前一个检查点的位置和 WAL 归档的状态。如果指定值时没有单位，则按兆字节计算。此参数只能在 \u003ccode class=\"filename\"\u003epostgresql.conf\u003c/code\u003e 文件中或服务器命令行上设置。\n       \u003c/p\u003e","doc":{"anchor":"GUC-WAL-KEEP-SIZE","file":"runtime-config-replication.html","lang":"en","sha256":"c0b8bd86131ec62d4df97ce480d004aa7e3544477d053f0c2d4047b9edad5cc0","slug":"18"},"doc_html":"\u003cp\u003e\n        Specifies the minimum size of past WAL files kept in the\n        \u003ccode class=\"filename\"\u003epg_wal\u003c/code\u003e\n        directory, in case a standby server needs to fetch them for streaming\n        replication. If a standby\n        server connected to the sending server falls behind by more than\n        \u003ccode class=\"varname\"\u003ewal_keep_size\u003c/code\u003e megabytes, the sending server might\n        remove a WAL segment still needed by the standby, in which case the\n        replication connection will be terminated.  Downstream connections\n        will also eventually fail as a result.  (However, the standby\n        server can recover by fetching the segment from archive, if WAL\n        archiving is in use.)\n       \u003c/p\u003e\u003cp\u003e\n        This sets only the minimum size of segments retained in\n        \u003ccode class=\"filename\"\u003epg_wal\u003c/code\u003e; the system might need to retain more segments\n        for WAL archival or to recover from a checkpoint. If\n        \u003ccode class=\"varname\"\u003ewal_keep_size\u003c/code\u003e is zero (the default), the system\n        doesn't keep any extra segments for standby purposes, so the number\n        of old WAL segments available to standby servers is a function of\n        the location of the previous checkpoint and status of WAL\n        archiving.\n        If this value is specified without units, it is taken as megabytes.\n        This parameter can only be set in the\n        \u003ccode class=\"filename\"\u003epostgresql.conf\u003c/code\u003e file or on the server command line.\n       \u003c/p\u003e","doc_same_as":"","documentation_revision":{"inputs":[{"file":"runtime-config-replication.html","kind":"same-version-reviewed-manual","locale":"en","sha256":"c0b8bd86131ec62d4df97ce480d004aa7e3544477d053f0c2d4047b9edad5cc0","version":"18.7"},{"file":"runtime-config-replication.html","kind":"same-version-reviewed-manual","locale":"zh-Hans","sha256":"83907b5f469e979a7b9ec875b5e7bdaa2ef6b85596ca31b45174f68cd7398b18","version":"18.7"}],"release":"18.7","runtime_remeasured":false,"source_revision":"pgdoc:b9f0e7232f60f380d642ac9b99226606c254b552"},"documented":true,"enumvals":null,"extra_desc":null,"lang":"en","max_val":"2147483647","metadata_version":"18","min_val":"0","name":"wal_keep_size","short_desc":"Sets the size of WAL files held for standby servers.","source":"pg-settings-source-snapshot","translation_provenance":{"inputs":[{"kind":"current-pgdoc-translation","path":"/Users/vonng/pgsty/pgdoc/zh/18/html/runtime-config-replication.html","sha256":"52bd5892f7e5511d05f46fc0c13a017de85307c674a9014948eb4ad480326c15"}],"kind":"same-version-pgdoc","locale":"zh-Hans","source_revision":"b1b500221dbe5437cfca004d6b04d3f6e422765d","version":"18"},"unit":"MB","vartype":"integer","zh_from":"same-version-manual"},"ManualEvidence":{"doc":{"anchor":"GUC-WAL-KEEP-SIZE","file":"runtime-config-replication.html","lang":"en","sha256":"c0b8bd86131ec62d4df97ce480d004aa7e3544477d053f0c2d4047b9edad5cc0","slug":"18"}},"MeasuredEvidence":{"metadata_version":"18"}},"Text":{"Collection":"guc","Key":"wal_keep_size","SourceDatabase":"center","Version":"18","Locale":"en","Title":"wal_keep_size","Summary":"Specifies the minimum size of past WAL files kept in the pg_wal directory, in case a standby server needs to fetch them for streaming replication. If a standby server connected to the sending server falls behind by more than wal_keep_size megabytes, 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 size 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_size 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. If this value is specified without units, it is taken as megabytes. This parameter can only be set in the postgresql.conf file or on the server command line.","BodyHTML":"\u003cp\u003e\n        Specifies the minimum size of past WAL files kept in the\n        \u003ccode\u003epg_wal\u003c/code\u003e\n        directory, in case a standby server needs to fetch them for streaming\n        replication. If a standby\n        server connected to the sending server falls behind by more than\n        \u003ccode\u003ewal_keep_size\u003c/code\u003e megabytes, the sending server might\n        remove a WAL segment still needed by the standby, in which case the\n        replication connection will be terminated.  Downstream connections\n        will also eventually fail as a result.  (However, the standby\n        server can recover by fetching the segment from archive, if WAL\n        archiving is in use.)\n       \u003c/p\u003e\u003cp\u003e\n        This sets only the minimum size of segments retained in\n        \u003ccode\u003epg_wal\u003c/code\u003e; the system might need to retain more segments\n        for WAL archival or to recover from a checkpoint. If\n        \u003ccode\u003ewal_keep_size\u003c/code\u003e is zero (the default), the system\n        doesn\u0026#39;t keep any extra segments for standby purposes, so the number\n        of old WAL segments available to standby servers is a function of\n        the location of the previous checkpoint and status of WAL\n        archiving.\n        If this value is specified without units, it is taken as megabytes.\n        This parameter can only be set in the\n        \u003ccode\u003epostgresql.conf\u003c/code\u003e file or on the server command line.\n       \u003c/p\u003e","SourceRevision":"wiki-repair-20261023:ee15467e323664f70e3c58869241aa78cd5b322ae4abcc517e956f3c4fa8e04f","ContentHash":"42031bc1433e51aea6021290bec913c3cca3dd1424b2e6c0039cb595572bae77","Payload":{"description":"Specifies the minimum size of past WAL files kept in the pg_wal directory, in case a standby server needs to fetch them for streaming replication. If a standby server connected to the sending server falls behind by more than wal_keep_size megabytes, 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 size 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_size 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. If this value is specified without units, it is taken as megabytes. This parameter can only be set in the postgresql.conf file or on the server command line."}},"RequestedLocale":"en","Fallback":false,"Versions":["13","14","15","16","17","18","19","20"],"Locales":["en","zh-Hans"],"Signatures":null,"Spellings":null,"SQLState":null,"Evidence":null}
