Skip to content

Initial setup for high availability

This guide provides instructions on how to set up a highly available PostgreSQL cluster with Patroni. This guide relies on the provided architecture for high-availability.

Considerations

  1. This is an example deployment where etcd runs on the same host machines as the Patroni and PostgreSQL and there is a single dedicated HAProxy host. Alternatively etcd can run on different set of nodes.

    If etcd is deployed on the same host machine as Patroni and PostgreSQL, separate disk system for etcd and PostgreSQL is recommended due to performance reasons.

  2. For this setup, we will use the nodes that have the following IP addresses:

    Node name Internal IP address
    node1 192.168.3.201
    node2 192.168.3.202
    node3 192.168.3.203
    HAProxy1 192.168.3.204
    HAProxy2 192.168.3.205
    backup 192.168.3.207

    We also need a virtual IP address for HAProxy: 192.168.3.208

Important

We recommend not to expose the hosts/nodes where Patroni / etcd / PostgreSQL are running to public networks due to security risks. Use Firewalls, Virtual networks, subnets or the like to protect the database hosts from any kind of attack.

Configure name resolution

It’s not necessary to have name resolution, but it makes the whole setup more readable and less error prone. Here, instead of configuring a DNS, we use a local name resolution by updating the file /etc/hosts. By resolving their hostnames to their IP addresses, we make the nodes aware of each other’s names and allow their seamless communication.

Run the following commands on each node.

  1. Set the hostname for nodes. Change the node name to node1, node2, node3, HAProxy1, HAProxy2 and backup, respectively:

    $ sudo hostnamectl set-hostname node1
    
  2. Modify the /etc/hosts file of each node to include the hostnames and IP addresses of the remaining nodes. Add the following at the end of the /etc/hosts file on all nodes:

    # Cluster IP and names
    
    192.168.3.201 node1    
    192.168.3.202 node2    
    192.168.3.203 node3    
    192.168.3.204 HAProxy1 
    192.168.3.205 HAProxy2 
    192.168.3.207 backup   
    

Next steps

Set up etcd