Top
Enterprise Postgres 18 SP1 Installation and Setup Guide for Server

4.7.15 Patroni

  1. Install Patroni and its associated support libraries using Python.
    To avoid conflicts with libraries already installed on your system and for ease of uninstallation, this guide demonstrates setup using a Python virtual environment.
    The following example uses "/venv/opt/patroni" as the virtual environment.
    Execute this as a user with write permissions to the "/venv/opt/patroni" directory.
    Additionally, if any additional support libraries are required, install them in the virtual environment in the same manner.

    python -m venv  /venv/opt/patroni
    source /venv/opt/patroni/bin/activate
    cd /opt/fsepv<x>server64/OSS/patroni
    pip install --no-index --find-links=./wheel ./wheel/*.whl
    #If additional installation is required
    pip install <additional library name>
  2. Add the path to the Patroni execution environment to the environment of the user running Patroni. The execution environment is "virtual environment/bin".

    export PATH=/venv/opt/patroni/bin:$PATH
  3. Configure Patroni to run as a service. As superuser, create the service system file (/etc/systemd/system/patroni.service).
    Below is an example configuration.
    Specify the virtual environment where Patroni is installed (/venv/opt/patroni) for "WorkingDirectory".
    <path> is the location of the Patroni configuration file required to run Patroni. The Patroni configuration file must be created beforehand.

    [Unit]
    Description=Patroni Master/Slave controller
    After=network.target etcd.service
    Wants=etcd.service
    
    [Service]
    Type=simple
    User=fepuser
    Group=fepuser
    
    WorkingDirectory=/venv/opt/patroni
    ExecStart=/venv/opt/patroni/bin/python3 -m patroni <path>/patroni.yml
    Environment="PATRONI_REPLICATION_PASSWORD=patpass" "PATRONI_SUPERUSER_PASSWORD=patpass"
    KillMode=process
    TimeoutSec=30
    Restart=no
    
    [Install]
    WantedBy=multi-user.target
  4. Create the Patroni configuration file (<path>/patroni.yml).
    Please create it by referring to the OSS manual.
    Important points to note during creation are documented as comments here for your reference.

    # Patroni configuration
    scope: patroni_cluster # Cluster name. Set to the same value on all servers.
    name: node1
    
    [Text omitted]
    
    # PostgreSQL configuration
    postgresql:
      data_dir: /home/fepuser/pg_pt
      bin_dir:  /opt/ fsepv<x>server64/bin
      connect_address: xx.yyy.zzzz.www:27500 # This server's IP address and PostgreSQL port
      listen: xxx.yyy.zzz.www:27500          # This server's IP address and PostgreSQL port
      # User and password for Patroni to connect to PostgreSQL
      # Specify the patroni_user and its password created in the service system file
      authentication:
        replication:
          username: patroni_user
          password: ${PATRONI_REPLICATION_PASSWORD}
        superuser:
          username: patroni_user
          password: ${PATRONI_SUPERUSER_PASSWORD}
    
        [Text omitted]
    
      pg_hba:
        # Replication users and superusers must be specified.
        - host replication patroni_user xx.yyy.zzz.0/24 md5 # Replication user
        - host all patroni_user xx.yyy.zzz.0/24 md5         # superuser (patroni_user)
        - host all all xx.yyy.zzz.0/24 md5                  # Other users (as needed)
        - host replication patroni_user XX.YY.ZZZ.0/24 md5
        - host all patroni_user XX.YY.ZZZ.0/24 md5
        - host all all XX.YY.ZZZ.0/24 md5
        - host all all xx.zz.yy.0/24 md5
    
    # initdb configuration
    initdb:
      - encoding: UTF8
      - locale: ja_JP.UTF-8
      - data-checksums # Required when using pg_rewind, etc.
    
    # Recovery operation settings
    recovery_conf:
      [Text omitted]
    
    
    # Etcd configuration
    etcd3:
      [Text omitted]
    
    
    # REST API Configuration (for Patroni health checks and management)
    restapi:
      [Text omitted]
    
    
    # Must be specified when running initdb with Patroni.
    bootstrap:
      dcs:
        postgresql:
          use_pg_rewind: true
    
    

4.7.15.1 Removing Patroni

  1. Delete the Python virtual environment.
    This example uses the virtual environment "/venv/opt/patroni".

    # rm -rf /venv/opt/patroni