Skip to content

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

ClickHouse 10 min read Case study hardMaster

Fencing a Postgres primary that might still be alive

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.

Related posts

  • 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.

  • Designing a reliable unplanned failover

    PlanetScale hardMaster

    Neki, 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.

  • Blocking cutovers to save replication slots

    PlanetScale mediumAdept

    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.

  • Building an enterprise Postgres service in ClickHouse Cloud

    ClickHouse easyNovice

    ClickHouse Cloud's managed Postgres runs on NVMe with up to two cross-AZ synchronous standbys using quorum commit (acknowledged when one standby confirms) and automatic failover. Standbys are deliberately kept off read traffic so WAL replay lag and VACUUM interference don't delay failover; separate read replicas handle read scaling. Other features include failover-safe logical replication slots that keep ClickPipes/PeerDB CDC into ClickHouse running across failovers without full resyncs, WAL-G daemon-based continuous archiving for 7-day PITR and forks, and per-cluster dedicated VPCs with TLS, AES-256 at rest and Private Link. Planned work includes GCP support, near-sub-second CDC v2, Query Performance Insights and Terraform support.

  • Managed Postgres on Railway

    Railway mediumAdept

    Railway's managed Postgres now covers the full database lifecycle: private-by-default services with reference-variable credentials, usage-billed vertical scaling, live volume resizing, and one-click PgBouncer pooling with a separate unpooled URL for migrations. HA conversion turns an existing node into the primary of a Patroni-managed streaming-replica cluster with etcd for leader election and HAProxy for routing, so apps keep the same endpoint through failover but still need reconnect/retry logic. Point-in-time recovery uses pgBackRest with continuous WAL archiving (weekly full, daily differential, ~4 weeks retention) and restores into a separate service. Automatic image updates, CVE patching, guided pg_upgrade major upgrades with compatibility checks, pg_stat_statements-based query statistics, and CLI/MCP agent workflows round out the platform.

The quest for software engineering knowledge.

Look:
Layout: