Installing and Configuring Patroni and etcd
Patroni is an open-source utility for PostgreSQL that automates failover and replica management. Patroni monitors the health of cluster nodes and promotes a standby to primary when the primary fails, ensuring continuity without manual intervention.
etcd is a distributed key-value store that Patroni uses as a distributed configuration store (DCS) to maintain cluster state and leader election. Patroni relies on etcd to coordinate which node holds the primary role and to store configuration data shared across all cluster nodes.
Before installing and configuring Patroni and etcd in a pgEdge Enterprise
Postgres (PEP) cluster, you need to
install and initialize
the Postgres database; the configuration steps require the location of an
empty data directory.
Installing Patroni and etcd
Use the following steps to install Patroni and etcd on a RHEL-based platform.
-
Review the platform-specific prerequisites for RHEL-based platforms at docs.pgedge.com.
-
Install pgEdge Enterprise Postgres; you'll find instructions at docs.pgedge.com. After installing pgEdge Enterprise Postgres, you can skip manual cluster initialization and postmaster startup. Patroni will perform both steps while bootstrapping.
-
Install the required Patroni and etcd packages with the following command:
bash sudo dnf install pgedge-patroni pgedge-patroni-aws \ pgedge-patroni-consul pgedge-consul pgedge-patroni-etcd \ pgedge-python3-etcd pgedge-patroni-zookeeper pgedge-etcd -
Verify the installed Patroni version with the following command:
/usr/bin/patroni --version -
Confirm that Python can import the Patroni module with the following command:
python3.12 -c "import patroni; print('OK')"
Configuring and Starting etcd
This section describes a single-node test setup for etcd. Use the following steps to configure and start the etcd service.
-
Open the etcd configuration file for editing:
sudo vi /etc/etcd/etcd.conf -
Add the following settings to the configuration file:
ETCD_NAME="default" ETCD_DATA_DIR="/var/lib/etcd/default.etcd" ETCD_LISTEN_CLIENT_URLS="http://localhost:2379" ETCD_ADVERTISE_CLIENT_URLS="http://localhost:2379" ETCD_ENABLE_V2="true" -
Enable and start the etcd service using the following commands:
sudo systemctl enable etcd sudo systemctl start etcd sudo systemctl status etcd -
Verify that etcd is working using the following command:
etcdctl endpoint health
Configuring and Starting Patroni
Use the following steps to configure and start the Patroni service.
-
Create the Patroni configuration directory and assign ownership to the
postgresuser:sudo mkdir -p /etc/patroni sudo chown postgres:postgres /etc/patroni -
Ensure the PostgreSQL
datadirectory is empty; Patroni uses the directory when it runsinitdb(during bootstrapping). If the directory does not exist, use the following commands to create it with the correct ownership and permissions:sudo mkdir -p /var/lib/pgsql/18/data sudo chown -R postgres:postgres /var/lib/pgsql/18 sudo chmod 700 /var/lib/pgsql/18/dataIf the directory already exists and contains data from a previous PostgreSQL installation, back up any important data and then remove the contents of the
datadirectory:sudo rm -rf /var/lib/pgsql/18/data/* -
Stop and disable the PostgreSQL service. Patroni manages PostgreSQL directly and must not share control with systemd:
sudo systemctl stop postgresql-18 sudo systemctl disable postgresql-18 -
Create the Patroni configuration file. For details about available configuration options, see the Patroni documentation:
sudo -u postgres vi /etc/patroni/patroni.yml -
Set the correct ownership and permissions on the configuration file:
sudo chown postgres:postgres /etc/patroni/patroni.yml sudo chmod 600 /etc/patroni/patroni.yml -
Enable and start the Patroni service using the following commands:
sudo systemctl enable patroni sudo systemctl start patroni sudo systemctl status patroni