How to do it...

For this recipe, we should already have three PostgreSQL servers. As usual, we'll assume they are named pg1, pg2, and pg3. If pg1 is the current primary, follow these steps to switch to ZooKeeper:

  1. Locate the myid file in the ZooKeeper configuration directory for each server.
  1. Assuming the server number in myid corresponds to the server name we've assigned (pg1, and so on), ensure the ZooKeeper configuration file on each server contains the following lines:
        server.1=pg1:2888:3888 
        server.2=pg2:2888:3888 
        server.3=pg3:2888:3888 
  1. If necessary, reload the ZooKeeper configuration file with the following command:
        sudo service zookeeper reload
  1. Execute this command as the postgres user on all nodes to stop Patroni, ending with ...

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.