# wal_keep_size

> A reloadable minimum amount of old WAL retained for streaming standbys that might fall behind. It is present from PG13 in this catalog, defaults to 0 MB, and is unmodified by all Pigsty templates.
---

> [!NOTE]
> **Fact — official short description:** “Sets the size of WAL files held for standby servers.”

## Identity {#identity}

| Field | Value | Meaning |
| --- | --- | --- |
| Type | `integer` | Upstream pg_settings type |
| Context | `sighup` | Takes effect after configuration reload |
| Unit | `MB` | Raw unit |
| Range | `0` – `2147483647` | Raw limits in the last observed version |
| Enum values | — | — for non-enum types |
| Category | Replication / Sending Servers | Upstream classification |
| Latest boot value | `0` | 0 B |
{.fields meta="-"}

## Lifecycle {#lifecycle}

| Fact | Value |
| --- | --- |
| First observed | PG13 |
| Present in | PG13–19 Beta 3 |
| Removed in | No |
| Introduction commit | [`f5dff45962ec`](https://git.postgresql.org/gitweb/?p=postgresql.git;a=commit;h=f5dff45962ec0a0daad443e45811d6c426be1237) — Rename wal_keep_segments to wal_keep_size. |
| Commit date | 2020-07-20 |
| Discussion | [thread 1](https://postgr.es/m/574b4ea3-e0f9-b175-ead2-ebea7faea855@oss.nttdata.com) |

## Default history {#default-history}

| Versions | Raw `boot_val` | Unit | Human value |
| --- | --- | --- | --- |
| PG13–19 Beta 3 | `0` | `MB` | 0 B |
{.full-width caption="Measured PG9.0–19 Beta 3 boot defaults"}

## How it works {#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.

## Tuning advice {#tuning-advice}

> [!TIP]
> **Advice.** These are workload-specific starting points and must be validated with measurements.

| Workload | Guidance |
| --- | --- |
| 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. |
| 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. |
| Small nodes | 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. |
{.full-width}

## Pigsty {#pigsty}

Values use the fixed 8-vCPU, 32-GiB, 100-GiB SSD fixture and render the current Pigsty templates for PG19 Beta 3; this does not assert current Pigsty support for that historical or beta release.

| Template | Effective value | Versus upstream boot | Source expression |
| --- | --- | --- | --- |
| OLTP | Unmodified | — | — |
| OLAP | Unmodified | — | — |
| CRIT | Unmodified | — | — |
| TINY | Unmodified | — | — |
{.full-width}

> [!CAUTION]
> **Advice — pending human review.** Fact from the current Pigsty template projection: OLTP: PG13–19 Beta 3 unmodified; OLAP: PG13–19 Beta 3 unmodified; CRIT: PG13–19 Beta 3 unmodified; TINY: PG13–19 Beta 3 unmodified. No Pigsty-specific rationale is inferred from an absent override.

## Common pitfalls {#common-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.

## Related parameters {#related-parameters}

[`wal_keep_segments`](/parameters/wal-keep-segments/) · [`max_replication_slots`](/parameters/max-replication-slots/) · [`max_slot_wal_keep_size`](/parameters/max-slot-wal-keep-size/) · [`archive_mode`](/parameters/archive-mode/) · [`max_wal_size`](/parameters/max-wal-size/) · [`primary_slot_name`](/parameters/primary-slot-name/)

## References {#references}

- [PostgreSQL 19 Beta 3 — wal_keep_size](https://www.postgresql.org/docs/19/runtime-config-replication.html#GUC-WAL-KEEP-SIZE)
- [PostgreSQL 18: Replication Slots](https://www.postgresql.org/docs/18/warm-standby.html#STREAMING-REPLICATION-SLOTS)
- [PostgreSQL 18: WAL Configuration](https://www.postgresql.org/docs/18/wal-configuration.html)
- [PostgreSQL 19 release notes](https://www.postgresql.org/docs/19/release-19.html)
- [Machine-readable GUC export](/data/guc.jsonl)
