There are many different solutions; but I would recommend and use a least a three node cluster using synchronous replication where one of the nodes is acting as the witness — at a minimum (actual have more replicas). The witness node need not be a full Postgres instance; it can also be achieved by using pg_recievexlog as the witness instead. This setup avoids a the split brain situation by making sure there is only one writable instance and that is the one that the witness is following. I use CARP (Common Address Redundancy Protocol) to manage the HA IP address (very platform specific); when the address flips over to a replica it automatically promotes the replica and witness follows the HA address thus signing off on the self promotion. The old primary then needs to be reconfigured as a replia which can be done using pg_rewind or other numerous other solutions; i.e. snapshots, backup, etc. I have not personally used this solution; but you could look at 2ndQuadrant repmgr product if you’re looking a packaged solution. https://www.2ndquadrant.com/en/resources/repmgr/installation-instructions/