In previous post, we installed Postgresql and ETCD on 3 nodes. In this post we will complete Patroni installation.
On the same Nodes (192.168.1.144, 145 and146)
First create Patroni Data directory.
mkdir -p /var/lib/postgresql/data
chown postgres:postgres /var/lib/postgresql/data
chmod 700 /var/lib/postgresql/data
Install Patroni
apt install -y patroni
mkdir -p /etc/patroni/
nano /etc/patroni/config.yml
config.yaml on Node1:
Change passwords and ip addresses according to your setup
scope: postgresql-cluster
namespace: /service/
name: postgresql-01 # node1
etcd3:
hosts: 192.168.1.144:2379,192.168.1.145:2379,192.168.1.146:2379 # etcd cluster nodes
protocol: http
restapi:
listen: 0.0.0.0:8008
connect_address: 192.168.1.144:8008 # IP for node1's REST API
bootstrap:
dcs:
ttl: 30
loop_wait: 10
retry_timeout: 10
maximum_lag_on_failover: 1048576 # Failover parameters
postgresql:
parameters:
pg_hba: # Access rules
- host replication replicator 127.0.0.1/32 md5
- host replication replicator 192.168.1.144/32 md5
- host replication replicator 192.168.1.145/32 md5
- host replication replicator 192.168.1.146/32 md5
- host all all 127.0.0.1/32 md5
- host all all 0.0.0.0/0 md5
initdb:
- encoding: UTF8
- data-checksums
postgresql:
listen: 0.0.0.0:5432
connect_address: 192.168.1.144:5432 # IP for node1's PostgreSQL
data_dir: /var/lib/postgresql/data
bin_dir: /usr/lib/postgresql/17/bin # Binary directory for PostgreSQL 17
authentication:
superuser:
username: postgres
password: YourPassword123 # Superuser password - be sure to change
replication:
username: replicator
password: YourPassword12345 # Replication password - be sure to change
parameters:
max_connections: 100
shared_buffers: 256MB
tags:
nofailover: false
noloadbalance: false
clonefrom: false
config.yaml on Node2
scope: postgresql-cluster
namespace: /service/
name: postgresql-02 # node2
etcd3:
hosts: 192.168.1.144:2379,192.168.1.145:2379,192.168.1.146:2379 # etcd cluster nodes
protocol: http
restapi:
listen: 0.0.0.0:8008
connect_address: 192.168.1.145:8008 # IP for node2's REST API
bootstrap:
dcs:
ttl: 30
loop_wait: 10
retry_timeout: 10
maximum_lag_on_failover: 1048576 # Failover parameters
postgresql:
parameters:
pg_hba: # Access rules
- host replication replicator 127.0.0.1/32 md5
- host replication replicator 192.168.1.144/32 md5
- host replication replicator 192.168.1.145/32 md5
- host replication replicator 192.168.1.146/32 md5
- host all all 127.0.0.1/32 md5
- host all all 0.0.0.0/0 md5
initdb:
- encoding: UTF8
- data-checksums
postgresql:
listen: 0.0.0.0:5432
connect_address: 192.168.1.145:5432 # IP for node2's PostgreSQL
data_dir: /var/lib/postgresql/data
bin_dir: /usr/lib/postgresql/17/bin # Binary directory for PostgreSQL 17
authentication:
superuser:
username: postgres
password: YourPassword123 # Superuser password - be sure to change
replication:
username: replicator
password: YourPassword12345 # Replication password - be sure to change
parameters:
max_connections: 100
shared_buffers: 256MB
tags:
nofailover: false
noloadbalance: false
clonefrom: false
config.yaml on Node3
scope: postgresql-cluster
namespace: /service/
name: postgresql-03 # node3
etcd3:
hosts: 192.168.1.144:2379,192.168.1.145:2379,192.168.1.146:2379 # etcd cluster nodes
protocol: http
restapi:
listen: 0.0.0.0:8008
connect_address: 192.168.1.146:8008 # IP for node3's REST API
bootstrap:
dcs:
ttl: 30
loop_wait: 10
retry_timeout: 10
maximum_lag_on_failover: 1048576 # Failover parameters
postgresql:
parameters:
pg_hba: # Access rules
- host replication replicator 127.0.0.1/32 md5
- host replication replicator 192.168.1.144/32 md5
- host replication replicator 192.168.1.145/32 md5
- host replication replicator 192.168.1.146/32 md5
- host all all 127.0.0.1/32 md5
- host all all 0.0.0.0/0 md5
initdb:
- encoding: UTF8
- data-checksums
postgresql:
listen: 0.0.0.0:5432
connect_address: 192.168.1.146:5432 # IP for node3's PostgreSQL
data_dir: /var/lib/postgresql/data
bin_dir: /usr/lib/postgresql/17/bin # Binary directory for PostgreSQL 17
authentication:
superuser:
username: postgres
password: YourPassword123 # Superuser password - be sure to change
replication:
username: replicator
password: YourPassword12345 # Replication password - be sure to change
parameters:
max_connections: 100
shared_buffers: 256MB
tags:
nofailover: false
noloadbalance: false
clonefrom: false
Restart Patroni service and check logs on all patroni nodes
systemctl restart patroni
journalctl -u patroni -f
patronictl -c /etc/patroni/config.yml list
In role section there must be 1 leader and 2 replicas. Note that, leader is running and replicas are streaming.
Right now we have an health Patroni Cluster. We should go back and edit ETCD environment file. Remember that ETCD Cluster State was set to "new". We should change it to "existing" on all etcd nodes.
nano /etc/etcd/etcd.env
Let's restart Patroni service.
systemctl restart patroni
Patroni setup is completed. In the next post, We will install and configure HAProxy and Keepalived services.