---
title: "Fencing a Postgres primary that might still be alive"
description: "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."
url: "https://swe.quest/articles/fencing-a-postgres-primary-that-might-still-be-alive-67043bdd5aea0f6c"
canonical: "https://clickhouse.com/blog/fencing-a-postgres-primary-that-might-still-be-alive"
source: "ClickHouse"
published: "2026-11-04"
difficulty: "hard"
kind: "Case study"
reading_minutes: 10
tags: ["postgres","replication","resilience","networking","cloud"]
---

# Fencing a Postgres primary that might still be alive

A post on [ClickHouse](https://swe.quest/sources/clickhouse.md), published 2026-11-04, 10 min read, Case study. Original: [https://clickhouse.com/blog/fencing-a-postgres-primary-that-might-still-be-alive](https://clickhouse.com/blog/fencing-a-postgres-primary-that-might-still-be-alive)

## Summary

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.

Written by swe.quest, not by the author.

**Difficulty:** Hard: written for specialists in the field

## Topics

- [PostgreSQL](https://swe.quest/tags/postgres.md) (Data & databases)
- [Replication](https://swe.quest/tags/replication.md) (Distributed systems)
- [Resilience](https://swe.quest/tags/resilience.md) (Distributed systems)
- [Networking](https://swe.quest/tags/networking.md) (Infrastructure)
- [Cloud platforms](https://swe.quest/tags/cloud.md) (Infrastructure)

## Prerequisites

- PostgreSQL streaming replication ([easy posts on PostgreSQL](https://swe.quest/tags/postgres.md?difficulty=easy))
- synchronous commit and WAL
- Linux network namespaces ([easy posts on Linux](https://swe.quest/tags/linux.md?difficulty=easy))
- AWS EC2 networking ([easy posts on Cloud platforms](https://swe.quest/tags/cloud.md?difficulty=easy))

## Keywords

PostgreSQL, Ubicloud, ClickHouse Managed Postgres, pg\_hba.conf, veth, AWS EC2, GCP Dynamic NIC, split brain

## Related posts

- [Designing a planned switchover for minimum disruption](https://swe.quest/articles/designing-a-planned-switchover-for-minimum-disruption-c09f9387b5a40465.md): PlanetScale · 2026-10-29 · Hard · 8 min read · PostgreSQL, Replication, Resilience, Deployment
  Neki performs planned Postgres primary switchovers without stopping the old primary.
- [Designing a reliable unplanned failover](https://swe.quest/articles/designing-a-reliable-unplanned-failover-ab0dd731f569d08c.md): PlanetScale · 2026-11-05 · Hard · 10 min read · PostgreSQL, Replication, Resilience, Distributed systems, Distributed databases
  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.
- [Blocking cutovers to save replication slots](https://swe.quest/articles/blocking-cutovers-to-save-replication-slots-d52d9d5fcc4a6789.md): PlanetScale · 2026-09-21 · Medium · 5 min read · PostgreSQL, Replication, Event-driven architecture, Deployment
  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.
- [Building an enterprise Postgres service in ClickHouse Cloud](https://swe.quest/articles/building-an-enterprise-postgres-service-in-clickhouse-cloud-d1a33138c29d5132.md): ClickHouse · 2026-02-20 · Easy · 5 min read · PostgreSQL, Replication, Event-driven architecture, Security
  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.
- [Managed Postgres on Railway](https://swe.quest/articles/managed-postgres-on-railway-38376e6923686bbc.md): Railway · 2026-11-05 · Medium · 9 min read · PostgreSQL, Replication, Cloud platforms, AI agents
  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.

Browse: [Latest posts](https://swe.quest/index.md) · [Topics](https://swe.quest/tags.md) · [Sources](https://swe.quest/sources.md) · [Topic map](https://swe.quest/map.md) · [Site guide (llms.txt)](https://swe.quest/llms.txt)
