---
title: "Fencing a Postgres primary that might still be alive"
description: "Promoting a Postgres standby does not stop the old primary from accepting writes, risking split brain or lost writes. DNS TTLs, bypassable synchronous replication, and existing connections keep the old primary writable. The control plane behind ClickHouse Managed Postgres fences the old primary by running multiple mechanisms in parallel and promoting as soon as the first succeeds. On bare metal, it runs ip link set vetho<vm> down on the host; on AWS, it detaches the secondary NIC with force: true ; on GCP, it deletes the Dynamic NIC. When every mechanism fails, the control plane still promotes because the design is fail-open, prioritizing availability over a stricter approach that would page a person."
---

# Fencing a Postgres primary that might still be alive

[Clickhouse](https://yomu.fyi/company/clickhouse) · Nov 5, 2026

**Type:** Problem & solution

## Summary

Promoting a Postgres standby does not stop the old primary from accepting writes, risking split brain or lost writes. DNS TTLs, bypassable synchronous replication, and existing connections keep the old primary writable. The control plane behind ClickHouse Managed Postgres fences the old primary by running multiple mechanisms in parallel and promoting as soon as the first succeeds. On bare metal, it runs ip link set vetho<vm> down on the host; on AWS, it detaches the secondary NIC with force: true ; on GCP, it deletes the Dynamic NIC. When every mechanism fails, the control plane still promotes because the design is fail-open, prioritizing availability over a stricter approach that would page a person.

## Context

A managed Postgres service must prevent writes to the old primary before promoting a standby to avoid split brain or lost writes. Promoting a standby does not stop the old primary from accepting writes: DNS TTLs let clients reach the old primary, synchronous replication can be bypassed by setting synchronous\_commit = local or by a client canceling a query, and existing connections persist. The control plane behind ClickHouse Managed Postgres runs on bare metal, AWS, and GCP, and each environment requires a different fencing mechanism.

## Approach / What changed

The control plane fences the old primary by running multiple mechanisms in parallel and promoting as soon as the first succeeds. On bare metal, it runs ip link set vetho<vm> down on the host. On AWS, it detaches the secondary (user) NIC with force: true . On GCP, it deletes the Dynamic NIC. Common mechanisms include pg\_stop (stops the cluster) and hba (writes a new pg\_hba.conf and reloads Postgres). When every mechanism fails, the control plane still promotes (fail-open design).

## Takeaways

- Promoting a standby does not stop the old primary from accepting writes; DNS TTLs, bypassable synchronous replication, and existing connections keep it writable.
- The control plane fences the old primary by running multiple mechanisms in parallel and promoting as soon as the first succeeds, minimizing downtime.
- The design is fail-open: when every fencing mechanism fails, the control plane still promotes the standby, prioritizing availability over a stricter approach.

## FAQ

### Why doesn't promoting a standby prevent split brain?

Promoting a standby does not stop the old primary from accepting writes. DNS TTLs let clients still reach the old primary, synchronous replication can be bypassed (e.g., by setting \`synchronous\_commit = local\`), and existing connections remain open. A client that cancels a commit query can still have the commit written in the old primary's WAL.

### How does the control plane fence the old primary quickly?

The control plane runs multiple fencing mechanisms in parallel and promotes as soon as the first one succeeds. On AWS, it detaches the secondary NIC. On bare metal, it runs \`ip link set vetho<vm> down\` on the host. On GCP, it deletes the Dynamic NIC. Common methods like \`pg\_stop\` and \`hba\` are also tried.

### What happens if all fencing mechanisms fail?

The design is fail-open: when every fencing mechanism fails, the control plane still promotes the standby. A stricter design would page a person and leave the database without a primary until someone acted, but the team chose availability over that stricter approach.

**Tags:** [AWS](https://yomu.fyi/topic/aws), [Bare Metal](https://yomu.fyi/topic/bare-metal), [Google Cloud](https://yomu.fyi/topic/gcp), [High Availability](https://yomu.fyi/topic/high-availability), [Postgres](https://yomu.fyi/topic/postgres)

- Source: [Clickhouse](https://clickhouse.com/blog/fencing-a-postgres-primary-that-might-still-be-alive)
- Source URL: https://clickhouse.com/blog/fencing-a-postgres-primary-that-might-still-be-alive
- Ingested by Yomu: 2026-11-04T15:00:11.287Z

[Read original post](https://clickhouse.com/blog/fencing-a-postgres-primary-that-might-still-be-alive)
