Thursday , September 28 2023

How To Create A PostgreSQL Cluster With Patroni

Today I will tell you How To Create A PostgreSQL Cluster With Patroni. I will be using Centos 7 as the operating system.

First of all, we will need 4 virtual servers with Centos 7 installed. You can access Centos 7 installation from the link below.

2. We install the epel repo on all our servers.

3. Then we restart our servers.

4. Install PostgreSQL 12 on pg_node1 and pg_node2.

5. We install Patroni on pg_node1 and pg_node2.

6. We create a config file for Patroni on pg_node1 and pg_node2.

We enter the configuration file with vi and edit it as follows.

For pg_node1 :

For pg_node2:

7. We install etcd on the etcd server.

8. After the installation is finished, we make the following changes in the configuration file.

9. We start the etcd service.

etcd service status

10. After starting the etcd service, we start the Patroni service in pg_node1 and pg_node2.

pg_node1 :

pg_node1 patroni status
pg_node2 :
pg_node2 patroni status

11. We install HAProxy on the haproxy server.

12. After the installation is finished, the configuration file is backed up and arranged as follows.

13. We start the HAProxy service.

HAProxy service status

If the HAProxy service cannot be started, we can check the errors in the configuration file with the following command.

When we open the address in the browser, we will see a haproxy panel like the one below. As can be seen here, pg_node1 is the master and pg_node2 is the slave.

We can also check the cluster status, role and members with the following command.

We have completed the cluster setup with Patroni. See you in my other articles.



About Melek Durdu

Leave a Reply

Your email address will not be published. Required fields are marked *