Quick revision
The short answer
First stop the divergence: remove one node from routing, usually the one that took fewer writes, and fence it so nothing can write to it. Before changing anything, capture both nodes' data and WAL, and find the divergence point from the timeline history and LSN. Then extract the transactions written to the losing node after the split, from audit tables, updated_at columns, application logs or WAL inspection, and reconcile them into the winner with business owners deciding conflicts. Rebuild the loser as a standby with pg_rewind or a fresh base backup, and run a postmortem on why fencing failed and two leaders were possible.
What to remember
In this answer, we responded to split brain by stopping writes on one node and fencing it, preserving both nodes' data and WAL, and finding the divergence point from timelines and LSNs. We extracted the losing node's writes from audit tables, timestamps, logs or WAL inspection, reconciled conflicts with business owners, rebuilt the loser with pg_rewind or a base backup, and used the postmortem to find why fencing failed and how two leaders became possible.
Your turn
Answer it aloud as you would in the interview, or type your answer below. Then show one part at a time and compare.
First stop the divergence: remove one node from routing, usually the one that took fewer writes, and fence it so nothing can write to it. Before changing anything, capture both nodes' data and WAL, and find the divergence point from the timeline history and LSN. Then extract the transactions written to the losing node after the split, from audit tables, updated_at columns, application logs or WAL inspection, and reconcile them into the winner with business owners deciding conflicts. Rebuild the loser as a standby with pg_rewind or a fresh base backup, and run a postmortem on why fencing failed and two leaders were possible.
Why this question is asked
This is the incident that high availability setups exist to prevent, and when it happens, the first hour decides how much data the company loses. Two PostgreSQL nodes report pg_is_in_recovery() = false, meaning both are acting as primaries, and both have taken writes for 4 minutes. Every additional minute adds more conflicting data, and every hasty action, such as restarting a node as a standby, can destroy the evidence we need. Interviewers ask this to see whether we can act fast and carefully at the same time. In this answer, we will stop the writes, preserve the evidence, find where the histories diverged, extract and reconcile the lost transactions, rebuild the losing node, and then fix the cause.
1Stop the Divergence Now
The priority is to make sure only one node accepts writes. We choose a winner, normally the node that the failover system now considers primary and that took most of the writes, since keeping its history means reconciling fewer transactions. The other node, the loser, is taken out of the routing layer, by removing it from the proxy or load balancer, moving the virtual IP or correcting DNS, and then fenced so no client with a cached address can still write to it.
Notice that we do not shut the losing node down or rebuild it yet. Setting it read-only and blocking its network access stops the damage while keeping its data intact. If we are unsure which node took more writes, we decide quickly with what we know and refine later; four more minutes of dual writes is worse than a slightly worse choice of winner. Pausing the failover manager also matters, so it does not make another automatic decision while we work.
2Preserve the Evidence and Find the Divergence Point
Before changing anything else, we take copies of both nodes: a snapshot of the losing node's data directory and its WAL, and the winner's WAL since the split. These copies are the only record of the writes that happened on the losing side, so we keep them until reconciliation is complete.
Then we find exactly where the histories split. When a standby is promoted, PostgreSQL starts a new timeline, a new branch of WAL history with a higher number, and writes a timeline history file that records the LSN, the WAL position, where the branch started. That LSN is the divergence point: everything before it is shared, and everything after it on each node is unique to that node.
3Extract the Losing Node's Writes
Now we need the list of changes made on the losing node after the divergence point. The easiest sources are application-level: tables with created_at or updated_at columns, an audit or outbox table, and application logs with request ids. A query on the losing node for rows changed in the four-minute window, compared with the winner, usually finds most of them.
For tables without timestamps, pg_waldump on the copied WAL shows the raw record-level changes after the divergence LSN, which tells us which tables and blocks changed, though turning that into rows takes work. Logical decoding is only an option if a logical replication slot already existed on the losing node before the split, because a new slot cannot read WAL from before it was created. This is why audit tables and change timestamps pay off in exactly this kind of incident.
4Reconcile With the Business
Each extracted change falls into one of three groups. Changes that do not conflict, such as a new order whose id is unused on the winner, can be replayed into the winner, often with a new id if sequences collided. Changes that conflict, such as an order id used on both sides or a balance updated on both, need a decision. And some changes triggered side effects outside the database, emails sent, payments captured, shipments started, which must be checked against those systems.
Engineers should not decide the conflicts alone. We prepare a list per business owner, for example finance for balances and payments and operations for orders, with both versions side by side, and they decide. Reconciliation scripts then apply the agreed outcome on the winner, each in a transaction, with a record of what was changed and why. Customers affected, for example by a double-sold item, may need to be contacted, which is again a business decision.
- Change from the losing nodeafter the divergence LSN
- Conflicts with the winner?YesSend to the business ownerNoReplay into the winner
- Check external side effectspayments, emails, shipments
- Apply the agreed outcome on the winnerlogged with the reason
4 steps in order. Play them, or step through them one at a time.
5Rebuild the Loser and Fix the Cause
Once its data has been extracted and saved, the losing node rejoins the cluster as a standby of the winner. pg_rewind makes this fast: it compares the two data directories from the divergence point and copies back only the blocks that changed, so the loser becomes a copy of the winner without a full base backup. It requires wal_log_hints = on or data checksums to have been enabled beforehand; otherwise we take a fresh base backup. Patroni can run pg_rewind for us when use_pg_rewind is enabled.
Finally, the postmortem asks the two questions that matter. Why did fencing fail: did the old primary not demote itself, was there no watchdog, did a proxy still route to it, did a client cache its IP? And why were two leaders possible at all: a two-node setup without a quorum, a failover manager with too short a TTL, an etcd cluster in one zone, or someone promoting a node manually? Each answer becomes a change, tested in a partition drill that deliberately cuts the network and checks that only one primary survives.
6Follow-up questions
Why not simply keep the winner and discard the loser's writes?
Because those four minutes may contain real orders and payments that customers were told succeeded. Discarding them means silently losing money or customer commitments. Sometimes the business decides that a few changes are not worth reconciling, but that is a decision to make knowingly, after seeing what they are.
What if the losing node took more writes than the winner?
Then it may be better to keep it as the winner, so fewer transactions need reconciling. The choice is about minimising reconciliation work and risk, not about which node the failover manager prefers. Whatever we choose, routing and the failover manager must agree on it.
How do you communicate during such an incident?
Declare a major incident early, name an incident lead, keep a timeline, and tell business owners as soon as data divergence is confirmed, because they need to prepare for reconciliation and customer contact. Clear, early communication prevents well-meaning people from making changes that destroy evidence.
7Conclusion
In this answer, we responded to split brain by stopping writes on one node and fencing it, preserving both nodes' data and WAL, and finding the divergence point from timelines and LSNs. We extracted the losing node's writes from audit tables, timestamps, logs or WAL inspection, reconciled conflicts with business owners, rebuilt the loser with pg_rewind or a base backup, and used the postmortem to find why fencing failed and how two leaders became possible.
Open with
My first goal is to stop it getting worse. I would pick a winner, usually the node the failover manager now treats as primary and that took more writes, pause the failover manager, take the other node out of the proxy or load balancer, and fence it, making it read-only and cutting its access, but without shutting it down or rebuilding it, because its data is the only copy of the writes made there.
Then, if they want more
Then I would snapshot both nodes' data and WAL. Next I would find the divergence point: the promoted node is on a new timeline, and its timeline history file gives the LSN where it branched, so everything the loser wrote after that LSN exists only on the loser.
To extract those writes I would use created_at and updated_at columns, audit or outbox tables and application logs, and pg_waldump for anything else; logical decoding only helps if a slot already existed.
Then reconciliation: non-conflicting changes are replayed into the winner, conflicts like duplicate order ids or double-spent balances go to the business owners to decide, and external side effects like payments are checked. Once that is done, I would rebuild the loser as a standby with pg_rewind, which needs wal_log_hints or checksums, or a fresh base backup.
Finally, a postmortem on why fencing failed and why two leaders were possible, for example a missing quorum or watchdog, followed by a partition drill to prove the fix.
About this answer
- Last updated
- 12 November 2026
- Checked
- Its structure and format are checked automatically. Use it as a carefully prepared study note: where a detail matters, confirm it against the documentation below. What the checks cover
- Where the question comes from
- Written by Scrivio for practice. It is not taken from an interview.
- Official documentation
- PostgreSQL documentation, MySQL reference manual
Report an issue with this answer
Copy the line below and send it to the author with what you found. It carries the address of this page.
Issue with "After a network blip, monitoring shows two PostgreSQL nodes reporting...": https://scrivio-interview-library.netlify.app/databases/replication-and-ha/8adcc9f841/