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 Consul:

  1. Execute this command as the postgres user on all nodes to stop Patroni, ending with the cluster leader:
        pkill -f patroni
  1. Remove these two lines from /etc/patroni/stampede.yml on each server:
        etcd: 
           host: ... 
  1. Add these two lines to /etc/patroni/stampede.yml on each server, remembering to substitute the proper server name:
        consul: 
            host: pg1:8500 
  1. Beginning with the former leader (pg1), start Patroni on all servers with this command:
        patroni /etc/patroni/stampede.yml \
            &> /var/log/postgresql/patroni.log

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.