Logical replication failover slots in PostgreSQL 17 and later

Failover-enabled logical slots and standby slot synchronization let subscribers and CDC pipelines resume after promotion. This page covers what to configure, how Patroni or operators fit in, and what to test.

On this page

What logical replication failover slots keep running after a failover

Logical replication failover slots let a CDC pipeline or logical subscriber keep its place after the primary fails and a standby is promoted. From PostgreSQL 17, a logical replication slot can be marked to be synchronized to standbys, so a consumer can resume from the new primary instead of being rebuilt from a fresh snapshot. Teams need this when a Debezium-style connector, a logical subscriber or an analytics feed reads changes from a primary that has a standby for high availability, and a failover would otherwise force a re-sync of large tables or risk lost or duplicated change events.

A physical standby failover and a logical consumer position are separate problems. Promotion moves the WAL stream to a new server, but a logical slot tracks a consumer's confirmed position in its own right, and that position is not carried over automatically in every setup. The slot must be created with failover enabled on the primary, and the standby must be configured to synchronize it, typically through sync_replication_slots and a physical replication slot that the standby uses to receive the primary's WAL. Confirm the exact requirements, including the PostgreSQL 17 behavior and any later changes, in the PostgreSQL high availability documentation before you rely on them.

PostgreSQL does not detect a primary failure or promote a standby by itself. Your failover tool, such as Patroni or a Kubernetes operator, decides when to promote, and it must also respect the settings that hold logical consumers back, such as synchronized_standby_slots. Plan a test in which you kill the primary during an active CDC run and check that the consumer resumes without gaps or repeated events. Record which tool owns promotion, which settings it changes, and who verifies the consumer position afterward.

How a logical slot follows the promoted standby

The diagram starts on the primary, where a logical slot decodes changes for the logical subscriber or CDC consumer. With synchronized_standby_slots, those changes are held at the wait until the named physical standby slot confirms it has flushed them, so the consumer never gets ahead of what the standby has. The failover tool (Patroni or an operator) promotes the standby, which already holds a copy of the slot through sync_replication_slots, and the consumer reconnects to the promoted standby. Check that the slot exists on the new primary and that the consumer resumes without gaps or duplicate changes.

Logical changes wait for the standby slot before the consumer resumes on the promoted server.

How failover slots and standby synchronization fit together

A logical replication slot survives a primary failover only if it is marked as failover-enabled on the primary and a standby carries a copy of it. The failover property is set when the slot is created, either with the failover option of CREATE SUBSCRIPTION or with the failover argument of the logical decoding functions that create slots. Marking the slot tells PostgreSQL that the slot should be propagated to standbys. On the standby side, sync_replication_slots must be enabled so that a background worker copies the slot's restart position and confirmed flush position from the primary into local slots. Those standby copies are what a consumer will find after promotion. Check the exact function arguments and parameter behavior for your PostgreSQL 17 or later minor release in the PostgreSQL documentation, since the details changed between releases.

A synchronized slot is only as current as the last position the standby received, so the copy can lag the primary's slot. If a consumer resumes on the promoted standby from a position the standby has not yet reached, it can miss changes or receive a position the new primary does not recognize. The safe rule is that a consumer should resume only after the promoted standby has replayed WAL at least to the confirmed position it last acknowledged, which is why the standby's catch-up state must be visible to the operator and the CDC pipeline. Test this on a staging cluster by writing changes, stopping the primary during replication, promoting the standby and comparing the subscriber's last applied position with the slot's position on the new primary.

The synchronized_standby_slots setting goes the other direction. It names the physical replication slots that must confirm receipt of WAL before logical decoding passes changes to subscribers or other logical consumers on the primary. This keeps a logical subscriber from getting ahead of the standbys that would be promoted in a failure. Each entry must match a physical slot that actually exists and is in use, so an entry for a slot that was dropped or is misnamed can stall logical decoding. Confirm the syntax, the list format and the behavior when a listed standby falls behind in the documentation for your version, and plan the trade-off that a lagging physical standby can hold back change delivery.

Which failover slot settings to choose

This table compares the configuration points that keep logical slots alive across a failover, with the situation each one fits and its trade-offs. Read each row as a decision: choose the setting that matches your consumers, then confirm the exact behavior in the documentation for your PostgreSQL version before you change production.

SettingWhen it fitsTrade-offWhat to confirm
Failover flag on slot creationLogical slots that a subscriber or CDC connector must resume from on a promoted standbySlots marked for failover depend on the standby being kept in sync, so a slot that lags the primary can lose its position after promotionExact syntax for creating or altering failover slots in your version, and which slot types the flag applies to
sync_replication_slots on standbysStandbys that should receive failover slot state from the primary and be ready to serve consumers after promotionThe standby does extra work to track slot progress, and the slot may only be as current as the last synchronizationWhether the setting is supported on your version, and the database and slot naming rules the standby needs
synchronized_standby_slots on the primarySetups where consumers must not get changes ahead of a standby that is not yet caught upLogical decoding can wait for the named standby slots, which can slow consumers when a standby falls behindHow the parameter lists standby slots, and what consumers see while they wait
hot_standby_feedback on standbysStandbys whose synchronized slots depend on the standby reporting its xmin back to the primaryFeedback can keep old row versions on the primary longer, which adds bloat and can increase replay pressureIts interaction with the synchronization worker and the monitoring you need on primary bloat
Database and slot namingAny cluster where the standby must find the same slot names and databases as the primaryA mismatch leaves synchronized slots missing or unused after promotion, so consumers restart from an older pointThe naming and database requirements in the version documentation, and a test that confirms the slot exists on the promoted node
Duplicate changes after promotionConsumers that can handle replayed events idempotently, such as Kafka sinks with stable keysSlots are not guaranteed to be perfectly current, so a consumer may receive some changes twice after promotionWhether your consumer deduplicates by key or log position, and how your team tests the restart

Setting up failover slots on PostgreSQL 17 and later

This sequence takes a PostgreSQL 17 or later primary with a logical subscriber or CDC client and produces a standby that carries logical slots through a failover, with a check at each step that proves the slots are moving.

  1. Confirm the PostgreSQL and consumer versions

    Confirm that the primary runs PostgreSQL 17 or later, that the standby will run the same major version, and that the subscriber or CDC client supports logical decoding from a slot that is synchronized to a standby. Your DBA checks the version with SHOW server_version; on each node, and the data platform owner confirms the client version against its own documentation. Record both before going further. The step is done when every node reports the same major version and the consumer team has written down the client version and its failover requirements. Confirm any behavior you rely on with the vendor of your CDC tool, since the PostgreSQL documentation describes the server side only.

  2. Create the physical standby with a replication slot

    Create a physical replication slot on the primary, then build the standby with pg_basebackup using that slot and start it as a hot standby. The DBA creates the slot with SELECT pg_create_physical_replication_slot('standby1'); and sets primary_slot_name on the standby. The standby also needs a valid primary_conninfo and must be able to read the primary's WAL. Verify the link by checking pg_stat_replication on the primary and confirming the standby reports streaming with a small replay lag. The step closes when the standby is streaming and the physical slot shows an active connection.

  3. Create the logical slot with failover enabled

    On the primary, create the logical replication slot with failover turned on so the server marks it as a candidate for synchronization to standbys. The DBA uses the failover option of the logical slot creation function that matches the decoding plugin in use, or the failover option of CREATE SUBSCRIPTION for a subscriber, and records the slot name. Confirm the setting in pg_replication_slots, where the failover column should read true for the slot. Check that the slot is not in use by a second consumer that would conflict with its name. The step closes when the slot is listed on the primary with failover set to true and the consumer is attached to it.

  4. Set sync_replication_slots on the standby

    On the standby, set sync_replication_slots to on so the standby copies failover-enabled logical slots from the primary and keeps them current. The DBA also confirms that the standby's primary_conninfo names a database the slot synchronization can use, and reloads the configuration. Check pg_replication_slots on the standby: the synchronized slot should appear with synced set to true and should not be used by any active consumer while the standby is still a standby. If the slot does not appear, check the standby's server log for messages about slot synchronization before changing any other setting. The step closes when the synchronized slot is visible on the standby.

  5. Set synchronized_standby_slots on the primary

    On the primary, set synchronized_standby_slots to name the physical standby slot that must confirm a change before logical consumers can receive it. This setting makes the logical slot wait for the named standby, so a consumer is never ahead of the standby that would be promoted. The DBA sets the value in postgresql.conf or with ALTER SYSTEM, reloads, and confirms the value with SHOW synchronized_standby_slots;. Document the trade-off: consumers may slow down if the named standby lags, so the owner of the CDC pipeline should know which standby is listed. The step closes when the setting is active and the consumer keeps receiving changes while the standby is caught up.

  6. Check that standby slot positions advance

    Generate a small amount of write traffic on the primary and compare the confirmed flush position of the logical slot on the primary with the position of the synchronized slot on the standby. The DBA queries pg_replication_slots on both nodes, reads confirmed_flush_lsn and restart_lsn, and confirms that the standby values move forward as the primary's values move. A value that stays behind for a long time points to lag, a missing synchronized slot, or a standby that cannot keep up with synchronized_standby_slots. The step closes when the positions advance together and the gap stays within the range your pipeline owner has agreed.

  7. Test consumer reconnection after a controlled switchover

    Run a controlled switchover in a non-production environment that matches your topology, promoting the standby and demoting the old primary. After promotion, the CDC client should reconnect to the new primary and resume from its saved position without a gap in the change stream. The operations team checks that the synchronized slot is now active on the new primary, that no change is lost or duplicated in the target system, and that the old primary rejoins as a standby. Record how long the consumer took to reconnect and what it had to do. The step closes when the consumer resumes cleanly in each test run and the results are documented for the runbook. Repeat the test after any major change to the PostgreSQL or consumer version.

Patroni, operators or hand-built failover: who manages the slots

In a Patroni cluster, the tool already decides which member is leader and reconfigures the standbys, so it is the natural place to define how replication settings reach every node. Logical slot behavior still depends on PostgreSQL settings that Patroni must apply consistently to each member. Confirm with your Patroni version's documentation which parameter keys it writes to the dynamic configuration and whether it manages the slot-related settings for you.

  • Configured by the tool: Patroni distributes PostgreSQL parameters from its dynamic configuration to all members, which is where settings such as sync_replication_slots are normally placed. Confirm the exact key names your version accepts.
  • Still set by your team: the logical slots, their output plugin, publications, subscriber settings and the consumer's own offset handling. Patroni does not create your CDC pipeline.
  • Reconnection: after a switchover or failover, point the connector at the cluster endpoint or the new leader, and confirm the slot exists on the promoted standby before traffic resumes.
  • Verification: run a planned switchover while changes flow, then check the slot on the new primary, its advancing position and that the consumer neither skips nor duplicates events.

Before relying on any of this, check the PostgreSQL failover documentation and your Patroni release notes for the parameters and their current behavior.

Failure modes that stop CDC after promotion

Logical replication slots live on one server, so a failover can leave CDC consumers with no slot, a stale slot or a connection to the wrong node. The cards below cover the failure modes we see most often, with the check that exposes each one before a consumer falls behind or loses changes.

Slot not marked for failover

A logical slot created without the failover option exists only on the primary. After promotion, the new primary has no slot to resume from, so the consumer either fails to start or creates a new slot at the current position and loses every change written in between. Check the failover flag on each slot with pg_replication_slots on the primary before the first failover test, and recreate any slot that shows it as false.

PostgreSQL failover docs

Standby slot lagging behind the consumer

Synchronized slots are copied to standbys, but the copy trails the primary. If the standby that receives the slot is behind the position the consumer has already confirmed, promotion moves the slot backward or leaves the consumer ahead of the new primary's WAL. Compare the confirmed_flush_lsn of each logical slot with the replay position on every standby, and alert when a standby falls behind a consumer's position.

Blocked delivery from missing standby

When synchronized_standby_slots names a standby that is down or unreachable, logical decoding waits until that standby catches up before sending changes to subscribers. Delivery stops even though the primary is healthy, which looks like a consumer outage. Check the setting against the standbys that actually exist, and confirm your runbook covers removing an unavailable standby from the list during an incident.

Duplicate or missed changes after promotion

A consumer that resumes from a position older than its last acknowledged change will receive duplicates, and one that resumes from a newer position will miss changes. Both depend on whether the slot position was synchronized correctly and whether the consumer commits offsets only after it has applied changes downstream. Test with a known sequence of writes across a switchover, then compare row counts and sequence values in the target system.

Consumers reconnecting to a demoted node

CDC connectors that hold a fixed host name or IP address may keep connecting to the old primary after it is demoted. The connection fails or, if the old node is restarted as a standby, the consumer can be pointed at a server that cannot serve logical decoding. Route consumers through the same leader-tracking mechanism your application uses, such as a Patroni-managed endpoint or a DNS record updated on promotion, and verify the connector reconnects to the new primary in a failover test.

What to test before go-live

Before a CDC pipeline depends on failover, run four failure tests against a staging copy of the production topology: a planned switchover with a live consumer, an unplanned primary stop, standby lag injection, and a consumer restart during promotion. The first test checks that the logical slot and its failover setting carry over to the new primary and that the consumer resumes without manual slot creation. The second checks the same thing when the primary dies without warning, which is the case that matters most because a standby may not yet have received the latest slot positions. The third delays WAL apply on a synchronized standby so you can see whether the slot-sync and synchronized_standby_slots settings hold the logical stream back as intended. The fourth restarts the consumer while promotion is underway, which exposes offset handling bugs that the other tests miss.

For each run, record the slot's confirmed flush position on the old and new primary, the consumer's committed offsets, the number of duplicate and missing change events downstream, and the time from failure to the first successfully consumed change. Compare the duplicate count with what your sink can absorb, since logical replication with failover is designed around at-least-once delivery and idempotent writes are the usual control. Define pass and fail criteria before the first run: for example, no lost committed changes, duplicates within an agreed bound, and resume time under a target your data consumers have signed off. The numeric targets are yours to set, and they should come from your recovery objectives, not from this page. Confirm the exact parameter behavior for your PostgreSQL minor version against the PostgreSQL high availability documentation before you write criteria that depend on it.

Write the results into a runbook that operators can follow without the test author present. Each test should list its trigger command, the expected state after each step, the queries that prove slot and offset state, and the rollback path if a check fails. Whether you use Patroni or an operator to drive the promotion, the runbook must name the tool, the commands that switch over and fail over, and who may approve a test in production. Repeat the full set after every major configuration change, including changes to Patroni, the consumer version or the sink, because a passing run on last quarter's setup proves little about today's cluster.

Security and operational considerations for replication slots

A logical replication slot is a promise from the primary to keep WAL until a consumer confirms it has been read. The cards below cover the access, encryption, monitoring, credential and audit controls that keep that promise from becoming a disk or availability problem, and they apply equally to failover-enabled slots that Patroni or an operator manages.

Replication role privileges

Create a dedicated replication role for each standby and a separate login role for each CDC consumer. Grant the replication attribute only where a standby or logical decoding connection needs it, and grant table SELECT only on the publications a consumer reads. Confirm that no consumer role can create or drop slots beyond what its pipeline requires, because a stray slot is a WAL retention risk the moment it is created.

Authentication methods

pg_hba.conf entries for consumers

Scope each pg_hba.conf line to a specific database, role, source network and the replication pseudo-database where needed. Avoid broad host entries that let any application subnet reach the replication port. Review these lines after every failover test, since a standby promoted or rebuilt from a new address can leave an old entry pointing at the wrong host or a host that should no longer have access.

TLS on replication connections

Require TLS for both streaming replication and logical decoding connections, using hostssl entries and a certificate policy your team can rotate. Replication traffic carries full row data for every published table, so an unencrypted path exposes the same content as a database dump. Ask the CDC vendor or connector to confirm it validates the server certificate rather than accepting any certificate.

Slot lag and WAL retention

An inactive slot holds WAL on the primary indefinitely until its consumer confirms progress or the slot is dropped. If a CDC pipeline stops, the primary keeps accumulating WAL, which can fill the data volume and take the primary offline, not just the pipeline. Monitor each slot's retained WAL and its activity state, alert on a slot that stops advancing, and agree in advance who may drop a slot and under what conditions.

Credential rotation for CDC users

Plan rotation for the consumer role's password or certificate without stopping the replication stream longer than needed. Store the credential in your secrets manager, not in connector configuration files on shared hosts. Confirm the connector can reload credentials, and test the rotation in a non-production environment, since a failed rotation on a consumer that is offline for days can leave a slot stranded.

Audit logging of slot changes

Enable logging that records connections, role changes and DDL, and keep a record of who created, altered or dropped a slot and when. Slot creation and removal change the primary's WAL retention behavior, so treat them like schema changes with a ticket and an approver. Confirm with your compliance team which log destinations and retention periods apply before you rely on the logs as evidence.

High availability docs

Questions teams ask before hiring help with failover slots

Can our team configure PostgreSQL failover slots without outside help?

Often yes, if the team already runs PostgreSQL replication and reads the failover and logical decoding documentation closely. The settings themselves are few, but the risk sits in the surrounding design: which consumers must survive a promotion, how each standby keeps its slots in step with the primary, and how the orchestration layer reports a promotion. A team with one subscriber, no external failover tooling and a long maintenance window can usually handle this in house. Teams with several CDC pipelines, Patroni or an operator managing the cluster, or downstream systems that cannot tolerate duplicate or missing change events should expect more testing before go-live. A short exercise in a non-production cluster will show whether your team can reproduce a failover and confirm that each consumer resumes cleanly.

What drives the effort on a failover slot project?

Four factors move the effort most:

  • Number of consumers: each logical slot needs its own decisions about failover behavior, monitoring and restart handling.
  • Orchestration: a cluster managed by Patroni or a PostgreSQL operator needs its configuration aligned with that tool, while a hand-built cluster needs custom promotion logic.
  • Consumer type: a Kafka Connect source connector, a custom subscriber and a different CDC tool each handle resumption and offsets differently, and each needs its own tests.
  • Testing scope: one planned switchover is far less work than a matrix of crash, network partition and disk fault tests run against every consumer.

Effort rises with each factor. A complete inventory of slots, consumers and their owners is the most useful input to any estimate, and it shortens the discovery phase of the work.

How long does failover slot work take, and what sets the duration?

No duration can be fixed responsibly before the environment is reviewed, so treat any figure given without that review as a guess. The length depends on how many consumers you run, whether the cluster already has a tested failover process, how many environments the change must pass through, and how many failure tests you require before production. Approval cycles for CDC owners, change freezes and the time needed to repeat tests after a fix also add calendar time. Ask for the schedule to be split into phases, with a review gate after each test cycle, so you can see where the time goes. DeployOpen's engagements are usually fixed-scope, which means the scope, deliverables and timeline are agreed in writing before work starts.

What does the work need from our team and environments?

Plan for access and people more than for hardware. You need a non-production PostgreSQL cluster that matches production topology closely enough to test promotion, plus access to the primary, the standbys and any orchestration layer. Confirm the PostgreSQL major version in each environment, because behavior depends on the release in use. PostgreSQL 17 is listed as supported until November 8, 2029, according to the PostgreSQL versioning policy. Each CDC owner must name their consumers, the offsets they expect, how much duplication they tolerate and their restart steps. Agree production change windows early, since the final switchover test usually interrupts consumers. Named contacts in the database, platform and data teams who can approve a test window save more time than almost any other input.

Do failover slots remove the need for failover runbooks?

No. Failover slots help keep logical replication slots available on a promoted standby, but PostgreSQL does not detect a failed primary or notify a standby on its own. That detection and promotion work belongs to an external tool such as Patroni or another orchestrator, as the PostgreSQL failover documentation explains. The sequence of promotion, fencing, client reconnection and consumer checks still has to be written down. Runbooks should also cover what the on-call engineer verifies after a promotion, how to recognize a consumer that has stalled, and when to pause a pipeline. Failover slots remove one class of manual work, such as recreating slots and recovering lost change events, but they make the operational procedure more important to get right.

What should a written quote for failover slot work include?

A quote should tie every line to a deliverable so you can compare proposals on the same basis. Ask for:

  • A slot and consumer inventory, listing each logical slot, its consumer and its owner.
  • The PostgreSQL versions, orchestration tool and cluster topology in scope.
  • A test matrix that names the failure modes, the environments where each runs and the pass criteria.
  • Deliverables such as configuration, runbooks, test reports and a retest after fixes.
  • Assumptions about client access, change windows and named contacts, with a statement of what changes if one slips.
  • Exclusions, such as changes to consumer application code or Kafka cluster operations, and who owns each excluded item.

A quote that cannot name its test cases or its assumptions is harder to hold a vendor to after work starts.

Limits and what to confirm in your environment

Failover-enabled logical slots depend on the exact PostgreSQL version, the failover tool, the subscriber or CDC client and the upgrade path. Each card below is a question to settle with the vendor or the version documentation before the design is final.

Exact PostgreSQL version and behavior

Confirm the precise major and minor version on every primary and standby, then read the documented behavior for that release. Failover slot support and the related parameters are version-specific, so a design validated on one release should not be assumed to hold on another. Check the support window for the version you run, since PostgreSQL 17 is supported to November 8, 2029, and plan minor updates around it.

Versioning policy

Failover-aware client resumption

Ask whether your CDC connector or subscriber client resumes from the slot after a primary change without re-reading or skipping changes. Some clients reconnect only to a fixed host and do not follow a promoted standby. Confirm the client's documented behavior on reconnect, its offset or LSN handling, and whether it needs a restart when the endpoint changes. Test this with a planned switchover before relying on it.

Failover tool parameter management

Confirm whether Patroni, your operator or your other failover tool sets sync_replication_slots and synchronized_standby_slots on each node, and whether it overrides values you set by hand. A tool that rewrites these settings on restart can silently change which slots are synchronized. Ask the vendor how the tool handles slots it did not create, and where the parameters appear in its configuration.

Logical decoding during promotion

Confirm what happens to in-flight logical decoding when a standby is promoted. Ask whether the promoted node holds the synchronized slot position, whether any changes committed on the old primary but not yet replicated can be lost or duplicated downstream, and how your subscriber reconciles that gap. Write down the answer for your own deployment and test it with a controlled failure.

Upgrade path and slot handling

Confirm whether moving from an earlier major version to 17 or 18 changes how existing logical slots are carried over. Major upgrades with pg_upgrade and logical replication handle slots differently, and slots may need to be recreated with failover enabled after the move. Check the upgrade notes for your source and target versions and plan a rehearsal on a copy of the cluster.

Upgrading docs

How DeployOpen scopes, delivers and supports this feature

DeployOpen approaches failover-enabled logical replication slots as a planned change to your PostgreSQL clusters and CDC pipelines, not a single setting. We agree the scope in writing, build and test the failover path in your own infrastructure, and hand over documentation and runbooks your team can operate after a primary failover.

How we scope

  • Inventory every logical subscriber, CDC consumer and slot, with its current major version and consumer behavior.
  • Confirm your PostgreSQL 17 or later target, your failover tool (Patroni or an operator) and your standby layout.
  • Agree in writing which slots, standbys and synchronization settings are in scope, and what is excluded.
  • Define acceptance tests for slot survival, consumer restart and lag, so the fixed-scope deliverables are measurable.

How we build

  • Enable failover on the affected slots and set sync_replication_slots on standbys, checking each change against your version.
  • Configure synchronized_standby_slots so logical consumers wait for the physical standbys they depend on.
  • Integrate the settings with Patroni or your operator's configuration so they survive a failover and rebuild.
  • Test failover with live CDC traffic, including a planned switchover and an unplanned primary stop, and record the results.

How we hand over

  • Deliver configuration, parameter rationale and a per-slot inventory stored in your own version control.
  • Provide a failover runbook covering slot checks, consumer restarts and recovery from a stalled slot.
  • Walk your operators through the test results and the monitoring for slot lag and inactive slots.
  • Document the open decisions, such as which consumers tolerate a replayed or missing change, for your owners to confirm.

How we support

  • Support is available as a retainer for upgrades, minor release updates and re-testing after topology changes.
  • Retesting covers any change to your failover tool, standby count, or consumer configuration.
  • Ask for the support scope, response expectations and testing cadence in the written quote before work begins.

Sources and further reading

Talk to our team.

Tell us what you're working on, whether it's a deployment, an audit, a security test or a cyber range. You'll speak with an engineer who can help you scope it.

  • 30-minute call: free, with no obligation.
  • NDA on request: we can sign before you share details.
  • Clear next steps: a scope and plan after the call.