Split-brain is the PostgreSQL high-availability failure that nobody notices until it is too late: two nodes accept writes at the same time, applications write different data to each one, and there is no clean way to merge them afterwards.
The good news is that detecting it takes two commands, and preventing it comes down to three design rules.
Detect it: two commands
Run this on every node of the cluster:
SELECT inet_server_addr (), pg_is_in_recovery (), timeline_id FROM pg_control_checkpoint ();
Enter fullscreen mode
Exit fullscreen mode
pg_is_in_recovery() = f means the node thinks it is a primary.…