Technology1 min read

Fencing a Postgres primary that might still be alive

By · Published by Everything Blog

In short

Standard promotion procedures and DNS changes do not reliably sever existing client sessions, risking lost writes across network partitions. Because promoting a standby relies entirely on isolating the old primary, any delay directly lengthens overall service downtime. To resolve this, the Ubicloud control plane runs multiple fencing mechanisms concurrently across environments like AWS, GCP, and bare metal, advancing as soon as the fastest method finishes.

Key points

  • Standard DNS modifications and promotion commands cannot immediately prevent active datab…: Standard DNS modifications and promotion commands cannot immediately prevent active database clients from writing to an original primary.
  • Unsuccessful primary fencing during a network partition risks severe data integrity issue…: Unsuccessful primary fencing during a network partition risks severe data integrity issues like split-brain conditions.
  • Running several fencing mechanisms simultaneously allows failover systems to proceed imme…: Running several fencing mechanisms simultaneously allows failover systems to proceed immediately once the fastest technique succeeds.

Sources checked by our analysis pipeline: 1

This post is based on my PGConf.EU 2026 talk, "The Primary Is Down. Are You Sure?".

A managed Postgres service needs to prevent any possible connections from writing into primary before promoting a new standby. This is called fencing, and it is important for preventing lost writes or split brain scenarios.

Why do we need to fence, if we are already promoting a standby?

To answer this, we need to first understand what a promotion looks like, and the steps involved to make a standby the new primary. Keep in mind that the old primary may not really be down. If we have a network partitioning where the client can connect to the primary but we cannot, the client can keep writing into the old primary.

Here are the steps:

-

We promote the standby by running

SELECT pg_promote(true, 300)

. At this point, this standby stops acknowledging commits from the primary. -

We refresh DNS records so new connections go to the new primary.

None of these steps stop the old primary from accepting writes, and that can cause…

Technology