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 cluster, you need to install pgEdge Enterprise Postgres.
Installing Patroni and etcd
Use the following steps to install Patroni and etcd on a Debian-based platform.
-
Install the required Patroni and etcd packages with the following command:
sudo apt-get install pgedge-patroni 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.
-
Copy the Patroni configuration template and set the required ownership and permissions. For details about available configuration options, see the Patroni documentation:
sudo cp /etc/patroni/config.yml.in /etc/patroni/config.yml sudo chown postgres:postgres /etc/patroni/config.yml sudo chmod 600 /etc/patroni/config.yml -
Ensure the Postgres
datadirectory is empty. Patroni runsinitdbduring bootstrap and requires an emptydatadirectory.If the directory exists and contains data from a previous Postgres installation, stop the service, back up any important data, and then remove the contents of the
datadirectory:sudo systemctl stop postgresql sudo systemctl disable postgresql sudo rm -rf /var/lib/postgresql/18/main -
Enable and start the Patroni service using the following commands:
sudo systemctl enable patroni sudo systemctl start patroni sudo systemctl status patroni