PostgreSQL Logical Replication Slots: A Managed Database Deep Dive
A practical guide to PostgreSQL logical replication slots, WAL retention, monitoring, failure modes, and safer managed database operations.
Logical replication slots are one of the most useful PostgreSQL features for zero-downtime migrations, change data capture, analytics pipelines, and selective data movement. They are also one of the easiest features to misunderstand operationally. A slot is small metadata inside PostgreSQL, but the promise it makes is large: keep the write-ahead log needed by a consumer until that consumer has safely received it.
That promise is exactly why replication slots are powerful. It is also why a forgotten slot can grow into a storage incident. In a managed PostgreSQL environment, the goal is not to avoid slots. The goal is to know when to use them, how to monitor them, and what to do when a subscriber falls behind.
The problem logical replication slots solve
PostgreSQL writes changes to the write-ahead log before data files are modified. Logical decoding can read those changes and present them as logical row-level change streams instead of physical block changes. Logical replication builds on that mechanism so a publisher can stream selected tables to a subscriber, while change data capture tools can stream changes into queues, warehouses, or search systems.
Without a replication slot, a consumer that disconnects has no durable claim on the WAL it still needs. PostgreSQL may recycle older WAL segments once they are no longer needed for crash recovery and other configured retention rules. A replication slot changes that behavior: the server remembers the consumer's confirmed progress and retains enough WAL for the consumer to resume from that point.
That is the core tradeoff. Slots improve correctness for replication consumers, but they move part of the consumer's failure budget onto the primary database's storage budget.
How a logical slot works
A logical replication slot has a name, a plugin, and progress state. For built-in logical replication, PostgreSQL uses the pgoutput plugin. Other tools may use output plugins such as wal2json or decoderbufs, depending on the environment and extension policy.
The most important state is the slot's restart position. PostgreSQL must retain WAL from that point because the consumer may still need it. As the subscriber receives and confirms changes, the slot can advance. If the consumer stops confirming progress, the retained WAL grows as writes continue on the publisher.
This behavior is visible in pg_replication_slots. PostgreSQL documents columns such as slot_type, active, restart_lsn, confirmed_flush_lsn, wal_status, and safe_wal_size. On newer PostgreSQL versions, those fields make it easier to distinguish a healthy inactive slot from one that is approaching WAL retention limits.
Slot failure modes in production
The common incident pattern is simple: a team creates a slot for a migration, a CDC connector, or a temporary subscriber; the consumer stops; writes continue; and WAL retention grows until the database approaches its storage limit. The slot itself is not large, but the retained WAL can be.
Another pattern is a slow consumer. Nothing is technically broken: the subscription remains connected, but it cannot apply changes as quickly as the publisher creates them. That can happen during a bulk import, a large schema migration, a network bottleneck, a subscriber-side index build, or a connector restart loop.
The third pattern is an invalidated slot. PostgreSQL can mark a slot unusable when required WAL is no longer available or when retention constraints are exceeded. In that case, the consumer usually needs to reinitialize from a fresh snapshot or another backup-consistent source. For migrations, this can turn a controlled cutover into a restart of the replication phase.
| Operational signal | What it usually means | Practical response |
|---|---|---|
Slot is inactive but restart_lsn is old | The consumer is disconnected and WAL is being retained | Reconnect the consumer, confirm it is still needed, or drop the slot deliberately |
| Retained WAL grows during normal writes | Consumer is not confirming progress fast enough | Check subscriber apply lag, network health, connector logs, and large transactions |
wal_status trends toward danger | The slot is nearing retention pressure | Reduce write volume if possible, repair the consumer, or plan a controlled resync |
| Slot exists after migration is complete | Temporary migration state was not cleaned up | Drop the slot after verifying no subscriber depends on it |
| Subscriber repeatedly resyncs tables | Apply workers cannot reach a stable state | Inspect schema compatibility, permissions, constraints, and long-running transactions |
Choosing when to use a slot
Use a logical replication slot when the consumer must not miss changes. That includes live migrations, blue-green database transitions, CDC into a durable downstream system, and multi-service architectures where another system needs an ordered stream of database changes.
Do not use a logical slot as a casual export mechanism. If a job only needs a one-time copy, pg_dump, a managed snapshot, or an application-level export is often safer. A replication slot is a standing operational contract between the publisher and a consumer. If nobody owns the consumer, nobody owns the WAL retention risk.
For managed PostgreSQL, the decision often comes down to ownership. A slot for a migration has a clear owner and a short life. A slot for a CDC pipeline needs an on-call owner, alerts, and a recovery plan. A slot created by an abandoned experiment is a liability.
A practical monitoring query
Start by reviewing the slots that exist and whether they are active. On PostgreSQL installations that expose WAL location functions and pg_replication_slots, a simple inspection query can estimate retained bytes for logical slots:
select
slot_name,
plugin,
slot_type,
active,
restart_lsn,
confirmed_flush_lsn,
pg_size_pretty(pg_wal_lsn_diff(pg_current_wal_lsn(), restart_lsn)) as retained_wal
from pg_replication_slots
where slot_type = 'logical'
order by pg_wal_lsn_diff(pg_current_wal_lsn(), restart_lsn) desc;
The exact function name depends on PostgreSQL version and environment. PostgreSQL 10 and later use pg_current_wal_lsn(), while older versions used pg_current_xlog_location(). Managed providers may also expose dashboard metrics for retained WAL, replication lag, or slot health. Prefer provider metrics for alerting when they are available, and keep the SQL query as a diagnostic tool.
A useful alert is not merely "slot inactive." Some legitimate migration slots may be inactive between controlled phases. A better alert combines inactivity with retained WAL growth, age since last progress, or distance from a storage threshold. The alert should route to the owner of the replication consumer, not only the database administrator.
Operational guardrails for managed databases
The safest slot policy is lifecycle-based. Before creating a slot, write down why it exists, which system consumes it, who owns that system, and when the slot should be removed. This can be as simple as a migration runbook entry, but it must be explicit. Slots without owners become storage problems months later.
For migrations, create the slot as late as practical, start the subscriber immediately, and monitor retained WAL throughout the backfill. Large initial copies can make replication appear stalled because the subscriber is busy copying base data before applying the stream. That is normal, but it still needs a storage budget. If the publisher is accepting heavy writes during the backfill, consider reducing write-heavy maintenance jobs until the subscriber catches up.
For CDC pipelines, treat the connector like production infrastructure. A Kafka Connect task, warehouse sync service, or custom decoding worker should have health checks and restart behavior that matches the importance of the stream. If the downstream system is down for a long time, the database will keep accumulating WAL until a configured limit, a storage limit, or an operator intervenes.
Managed PostgreSQL changes some responsibilities but not the physics. The provider may automate backups, patching, storage alarms, and high availability. The application team still needs to decide which slots are expected, which slots are temporary, and how much WAL retention is acceptable for each consumer.
Drop slots carefully, not fearfully
Dropping an unused slot is safe when no consumer depends on it. Dropping an active or needed slot is disruptive because the consumer loses its resume point. The right process is to identify the slot owner, stop or confirm the consumer state, verify that another initialization path exists if needed, and then drop the slot intentionally.
For a completed migration, cleanup belongs in the cutover checklist. After the application is writing to the new database and the old publisher is no longer needed for rollback, remove subscriptions, publications, and slots associated with the transition. Leaving the old slot in place does not make rollback safer if nobody is maintaining the subscriber. It only keeps old WAL obligations alive.
Publications, schema changes, and edge cases
Logical replication is not the same as physical replication. It replicates data changes according to publications and subscriptions. Schema changes require separate handling unless tooling around the migration applies them on both sides. If a table is missing a suitable replica identity, updates and deletes may not replicate the way the application expects. The PostgreSQL documentation explains publication behavior, replica identity, subscriptions, and restrictions in detail, and those details matter for production migrations.
Large transactions are another edge case. The consumer may not be able to confirm progress until it has processed a large transaction, so retained WAL can jump even when the system is functioning. Long-running transactions on the publisher can also make operational interpretation harder because progress may not look smooth. When planning a migration, avoid mixing a large bulk rewrite, a major application deploy, and a logical replication cutover in the same window.
Version differences matter as well. PostgreSQL has improved logical replication observability and behavior over time, and managed providers may expose a subset of extensions or configuration knobs. Before choosing a CDC tool or migration strategy, check whether the provider supports the required output plugin, publication options, slot limits, and relevant monitoring views.
Recommended runbook
A good runbook is short enough that engineers will actually use it. Create the slot with a clear name that includes the consuming system or migration. Record the owner and expected removal date. Confirm that the consumer is connected and advancing. Monitor retained WAL during backfill and catch-up. Pause high-write batch jobs if the subscriber falls behind. After cutover or decommissioning, drop the slot and verify that retained WAL returns to normal.
If retained WAL is already growing, resist the urge to drop first and ask questions later. Identify whether the slot is part of an active migration, a CDC pipeline, or an abandoned test. If it is active, repair the consumer and watch the confirmed flush position advance. If the consumer cannot recover, plan a resync so the team understands the data consequences. If it is abandoned, drop it and document why.
ArmorDB users who want simpler operations should combine this runbook with managed backups, clear migration windows, and PgBouncer-aware application rollout practices. Our backup guide and migration strategy comparison cover the surrounding decisions that often determine whether a slot-based migration stays boring.
Takeaway
Logical replication slots are not dangerous by themselves. Unowned slots are dangerous. A well-run managed PostgreSQL environment can use slots confidently for migrations and change streams as long as every slot has an owner, a consumer, an alert, and an end-of-life plan.
The practical rule is simple: create slots deliberately, monitor retained WAL, and delete slots deliberately when their job is done. That turns logical replication from a hidden storage risk into one of the most useful tools in the PostgreSQL operations toolbox.
Sources and further reading
Topic
Deep Dives
Updated
Jul 27, 2026
Read time
9 min read
ArmorDB Engineering writes about PostgreSQL operations, security, and infrastructure decisions for teams building production apps on ArmorDB.
Read next
Tech-News & Trends · 7 min read
PostgreSQL 19 Beta 2: What Managed PostgreSQL Teams Should Test
PostgreSQL 19 Beta 2 is a useful checkpoint for testing authentication, migration, replication, and SQL compatibility before a future managed PostgreSQL upgrade.
Read articleData-Specs / Vergleiche · 8 min read
PostgreSQL Connection Pooling Options Compared for Production Apps
Compare direct PostgreSQL connections, application pools, PgBouncer, and managed pooling so you can choose the right connection architecture for a growing app.
Read article