In the event of a disaster, a standby should be promoted to a master. This is to limit the amount of downtime involved when the master cannot be brought up for a longer period. While it is tricky to perform failover in some relational databases, it is very easy with PostgreSQL. We shall discuss how a standby can be promoted to a master in simple steps in this recipe.
Getting ready...
We must ensure that at least one standby has been set up for replication to perform a promotion or a failover. In the event of a failover, when the primary/master is lost, any transaction committed on the master that was not already synced/applied to the standby may be lost. Either the application should be designed to handle such situations and apply any lost transactions or we must wait until the recovery is completed, when the required WALs containing those transactions are already shipped to the standby.
Synchronous replication minimizes the possibility of losing transactions...