Lesson 3 of 14

Replication Slots: Guaranteeing WAL Retention

Applies to PostgreSQL 13–17 Last reviewed May 2026 Grounded in source

The one thing to understand first

A replica (physical standby or logical subscriber) consumes WAL from the primary. If the primary recycles WAL before the replica has read it, the replica falls irrecoverably behind and must be rebuilt. The old wal_keep_size approach — keep a fixed amount of WAL and hope it’s enough — is fragile. Replication slots solve this precisely by tracking exactly how far each consumer has progressed and retaining WAL until then.

A slot is a promise the primary makes to a consumer: “I will keep this WAL until you read it.” The catch is that the promise has no expiry — make it to a consumer that never returns and it becomes a promise to fill your own disk.

How a slot works

A slot (src/backend/replication/slot.c) is a named, persistent marker recording the oldest WAL position (restart_lsn) a consumer still needs. The primary will not remove WAL beyond that position. Slots survive restarts, so a standby can disconnect, come back hours later, and resume from exactly where it stopped — no rebuild required.

This is a Pro lesson

Get every Learning Pathway and cookbook recipe — grounded in PostgreSQL source code, with diagnostics, fixes, and prevention for each topic.

Continue this lesson to learn:

  • Logical slots also pin the catalog horizon
  • Layer 3 — Watch it happen on your own database
  • Layer 4 — The levers this hands you
  • Layer 5 — What an Oracle DBA should expect vs what they get
  • Key takeaway
  • How this article was written
  • All 36 Learning Pathway lessons
  • 170+ cookbook recipes
  • Source-grounded diagnostics & fixes

Secure checkout Cancel anytime Source-grounded

Was this helpful?

← Back to 04 — Advanced: Replication & HA Architecture