How to do it...

For the purposes of this recipe, pg-primary will remain our master node, and the replica will be pg-clone. As always, the /db/pgdata path will be our default data directory.

Follow these steps to promote pg-clone to be the new cluster master:

  1. Stop the PostgreSQL service on the pg-primary node with pg_ctl:
        pg_ctl -D /db/pgdata stop -m fast
  1. As the postgres user on pg-clone, execute this command to promote it from standby status to primary:
        repmgr -f /etc/repmgr.conf standby promote
  1. View the status of the cluster with this command as postgres on pg-clone:
        repmgr -f /etc/repmgr.conf cluster show

Follow these steps to rebuild pg-primary (while logged into pg-primary) to be the new cluster standby:

  1. Erase the contents ...

Get PostgreSQL High Availability Cookbook - Second Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.