Skip to content

In development. Expect rough edges and changes. The source code is not public yet.

PlanetScale 5 min read How-to mediumAdept

Blocking cutovers to save replication slots

PlanetScale Postgres blocks planned cutovers (resizes, parameter changes, maintenance) when logical replication slots aren't synchronized to the replica being promoted, because vanilla Postgres will promote a replica without the slot and silently break CDC consumers. To make slots promotion-ready, create them with failover = true (or ALTER_REPLICATION_SLOT ... (FAILOVER true)) and set hot_standby_feedback and sync_replication_slots to on. The operator detects misconfiguration, alerts users, waits for slots to be ready, and manages synchronized_standby_slots. Enabling hot_standby_feedback pins the primary's vacuum horizon and can add bloat, which is why both settings are off by default.

Related posts

  • ClickPipes for Postgres now supports failover replication slots

    ClickHouse mediumAdept

    Postgres ClickPipes can now create logical replication slots with failover enabled, so CDC pipelines into ClickHouse survive a primary-to-standby promotion. The feature depends on Postgres 17 logical replication failover. Both primary and standby must run Postgres 17+, with the standby using a physical replication slot and synchronous commit configured. hot_standby_feedback and sync_replication_slots must be enabled on the standby, and the standby's physical slot must be added to synchronized_standby_slots on the primary so the standby never lags the ClickPipe. You can confirm it works by checking pg_replication_slots on the standby for a mirror_ slot with synced and failover set to true.

  • Designing a planned switchover for minimum disruption

    PlanetScale hardMaster

    Neki performs planned Postgres primary switchovers without stopping the old primary. Routers buffer primary-bound queries, the primary is set read-only by default, and every replica except the target is disconnected so its receive_lsn fixes a final WAL position the target must replay through. Preflight checks cover shard state, failover slots and capacity settings such as max_connections, and post-convergence checks cover slots and having at least one synchronous standby attached. If any check fails before promotion, a config reload makes the old primary writable again for a fast rollback. With ANY 1 synchronous replication and synchronous_commit=on, every acknowledged commit is present on the target when it is promoted.

  • Fencing a Postgres primary that might still be alive

    ClickHouse hardMaster

    Before promoting a standby, a managed Postgres control plane must fence the old primary, because promotion and DNS changes alone don't stop writes: async standbys, per-session synchronous_commit overrides, quorum commit with a remaining standby, and canceled commits already in WAL can all let a still-alive primary accept writes. Ubicloud's control plane (behind ClickHouse Managed Postgres) runs several fencing mechanisms in parallel and proceeds on the first success. The SSH-based ones are pg_ctlcluster stop, which a start.conf auto-start undoes on reboot, and a pg_hba lockout, which misses existing connections. The platform-specific ones are setting the host-side veth down on bare metal, force-detaching a dedicated secondary user NIC on AWS, and deleting a Dynamic NIC on GCP, where traffic stopped within 0.7–2.5s. If every mechanism fails, the design is deliberately fail-open and promotes anyway, choosing availability over a guaranteed fence.

  • When SIGTERM Does Nothing: A Postgres Mystery

    ClickHouse hardMaster

    Creating a logical replication slot on a Postgres hot standby (v16+) can hang indefinitely and ignore pg_cancel_backend and pg_terminate_backend when a transaction is still open on the primary. The cause is XactLockTableWait: on a standby, LockAcquire returns immediately while TransactionIdIsInProgress still sees the primary's transaction via KnownAssignedXids. The function therefore spins in a 1ms pg_usleep loop with no interrupt check and no wait_event, which left a WAL-retaining slot that only a full restart could clear. A one-line CHECK_FOR_INTERRUPTS patch was accepted and backported to all supported versions, and a new wait event plus more efficient standby waiting are proposed for Postgres 19.

  • Patching the PostgreSQL JDBC Driver

    Zalando Engineering mediumAdept

    Postgres logical replication slots for clients watching low-traffic tables never advance, so the server retains all WAL generated by other tables until disk fills and the node goes read-only. Zalando fixed this upstream in PgJDBC: the driver now tracks the last received and last confirmed replication LSNs, and when they match and a KeepAlive message reports a higher server LSN, it confirms that LSN, safely advancing the slot without skipping relevant events. The fix, merged for PgJDBC 42.7.0, removes the need for the common dummy-write workaround and was validated by comparing WAL size graphs before and after a patched Debezium image rollout across hundreds of event streams.

The quest for software engineering knowledge.

Look:
Layout: