Designing a planned switchover for minimum disruption
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.
Related posts
- Designing a reliable unplanned failover
PlanetScale hardMasterNeki, PlanetScale's Postgres sharding system, declares a primary dead only when its control plane (Admin) cannot reach it and at least one reachable replica reports broken replication with none contradicting. Under ANY 1 synchronous replication, that means the primary can no longer commit. Short TCP keepalives, tcp_user_timeout and wal_receiver_timeout make crashes, dropped packets and frozen processes all surface as broken replication. Admin then blocks reconnection by prefixing the old primary's hostname in primary_conninfo with "//", which also freezes WAL positions, and promotes the replica that has replayed through the highest received LSN so the others can follow on the new timeline. The old primary is fenced as TEARDOWN rather than rejoined, since it may hold writes the new primary lacks and is kept for postmortem.
- 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 failover isn’t safe: Building high-availability PostgreSQL on Kubernetes
Datadog Engineering mediumAdeptA staging gameday simulating zonal network latency left Datadog's Kubernetes-hosted PostgreSQL clusters stuck: with asynchronous replication, every standby exceeded Patroni's maximum_lag_on_failover, so no failover candidate could be promoted safely. The fix is a hybrid model in which leader-pool standbys replicate synchronously while read replicas stay asynchronous. Patroni is configured with synchronous_mode, synchronous_node_count=1 and synchronous_mode_strict, and PostgreSQL with synchronous_commit=remote_apply, so a failover candidate is always current. pgbench TPC-B benchmarks across synchronous_commit levels quantify the latency and throughput cost of each durability option.
- Blocking cutovers to save replication slots
PlanetScale mediumAdeptPlanetScale 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.
- Production Postgres on Railway: From First Deploy to High Availability
Railway mediumAdeptRailway Postgres can grow from a single private-networked database to a production setup with volume backups, point-in-time recovery, PgBouncer connection pooling and Patroni-based high availability, demonstrated with an orders API that uses idempotency keys so retries stay safe. PITR restores into a separate service for validation, and the guide stresses measuring RPO/RTO end to end, including validation and reconnection time. Transaction pooling breaks session settings, LISTEN, advisory locks and named prepared statements, so migrations should use an unpooled URL. In one small planned switchover test (primary, two replicas, etcd, HAProxy), writes were interrupted for about 17 seconds. That is a single observation, not a guaranteed failover time.