Configuring Patroni software

Follow these steps to configure Patroni for the HA setup.

Procedure

Configure Patroni by using a YAML configuration file by using the following steps:
  1. Create the patroni_config.yaml file and add the following content:
    vi patroni_config.yaml
    scope: <CLUSTER_NAME>
    name: <NODE_NAME>
    
    restapi:
      listen: <NODE_IP_address>:8008
      connect_address: <NODE_IP_address>:8008
    
    etcd:
       host: <ETCD_IP_address>:2379
    
    bootstrap:
      dcs:
        ttl: 30
        loop_wait: 10
        retry_timeout: 10
        maximum_lag_on_failover: 1048576
        postgresql:
          use_pg_rewind: true
          use_slots: true
      initdb:  
      - encoding: UTF8
      - data-checksums
    users:
       <USER1>:
          password: <user_password>
          options:
            - createrole
            - createdb
    postgresql:
      listen: <NODE_IP_address>:5432
      connect_address:<NODE_IP_address>:5432
      data_dir: <DATA_DIR>  bin_dir:  <BIN_DIR>  
      pgpass: /tmp/pgpass0
      authentication:
        replication:
          username: replicator
          password: <replicator_password>
        superuser:
          username: postgres
          password: <super_user_password>
        parameters:
          unix_socket_directories: '.'
    pg_hba:
        - local all all md5
        - host all all 0.0.0./0 md5
        - host replication replicator 127.0.0.1/32 md5
        - host replication replicator <Node1_IP_address>/32 md5
        - host replication replicator <Node2_IP_address>/32 md5
        - host replication replicator <NodeN_IP_address>/32 md5
    tags:
        nofailover: false
        noloadbalance: false
        clonefrom: false
        nosync: false
      
    Where,
    • <CLUSTER_NAME>

      The common name of your choice for this cluster.

    • <NODE_NAME>

      The unique name of your choice for this node.

    • <NODE_IP_address>

      The IP address or hostname for this node.

    • <ETCD_IP_address>

      The IP address or hostname where etcd instance is running.

    • <Node1_IP_address>, <Node2_IP_address>, and <NodeN_IP_address>

      The IP addresses or hostnames for PostgreSQL instances that are running on different systems in this cluster.

    • <USER1>

      The additional username must be created while initializing cluster. You can create many users by replicating <USER1> YAML block with unique username and password for each user you want to add.

    • <USER1_PASSWORD>

      The password for additional user <USER1>.

    • <BIN_DIR>

      The PostgreSQL bin directory on this node.

    • <DATA_DIR>

      The PostgreSQL data directory on this node.

    • <REPLICATOR_USER_PASSWORD>

      The password for replicator user.

    • <SUPER_USER_PASSWORD>

      The password for superuser.

What to do next

Do the following tasks:
  • Validate the YAML file before you proceed to the next step.
  • You can choose the super username and replicator username and in that case you must create the super user as the Operating system user.
  • You can add more users to the PostgreSQL cluster. For that you must repeat the configuration for <USER1> YAML block with different user details.