<!--DEBUG:--><!--DEBUG:dc3-united-states-software-in-english-pdf-2--><!--DEBUG:--><!--DEBUG:dc3-united-states-software-in-english-pdf-2--><!--DEBUG-spv-->{"id":1967948,"date":"2021-08-15T03:36:00","date_gmt":"2021-08-15T01:36:00","guid":{"rendered":"http:\/\/nhub.news\/?p=1967948"},"modified":"2021-08-15T05:05:58","modified_gmt":"2021-08-15T03:05:58","slug":"how-to-set-up-postgresql-high-availability-with-patroni","status":"publish","type":"post","link":"http:\/\/nhub.news\/ru\/2021\/08\/how-to-set-up-postgresql-high-availability-with-patroni\/","title":{"rendered":"How to Set Up PostgreSQL High Availability With Patroni"},"content":{"rendered":"<p style=\"text-align: justify;\"><b>This guide demonstrates how you can create a PostgreSQL High Availability cluster with Patroni, etcd, and HAProxy on Ubuntu 20.04.<\/b><br \/>\nJoin the DZone community and get the full member experience. PostgreSQL is an open-source, versatile, and most popular database system around the world. However, it does not have any features for high availability. Enter Patroni. Patroni is a cluster manager tool used for customizing and automating deployment and maintenance of high availability PostgreSQL clusters. It is written in Python and uses etcd, Consul, and ZooKeeper as a distributed configuration store for maximum accessibility. In addition, Patroni is capable of handling database replication, backup, and restoration configurations. In this guide, we will show you how to set up a four-node PostgreSQL cluster with Patroni on Ubuntu 20.04. Use the following setup to identify the IP address and application of each node. The first step you will need to do is to install the PostgreSQL server on node1 and node2. Run the following command to install PostgreSQL on both nodes. apt install postgresql postgresql-contrib -y After the installation, you will need to stop the PostgreSQL service on both nodes: systemctl stop postgresql Next, you will need to symlink \/usr\/lib\/postgresql\/12\/bin\/ to \/usr\/sbin because it contains tools used in Patroni. ln -s \/usr\/lib\/postgresql\/12\/bin\/* \/usr\/sbin\/ First, install all the required dependencies on node1 and node2 using the command below: apt install python3-pip python3-dev libpq-dev -y Next, run the following command to upgrade PIP to the latest version: pip3 install &#8212;upgrade pip Finally, use the PIP command to install the Patroni and other dependencies on both node1 and node2: At this point, Patroni has been installed on node1 and node2. Next, go to node3 and install the ETCD using the command below: apt install etcd -y After the successful installation, log in to node4 and install the HAProxy using the command below: apt install haproxy -y The ETCD main configuration file is located at \/etc\/default\/etcd. Edit the \/etc\/default\/etcd file using your favorite editor on node3: nano \/etc\/default\/etcd Add the following configuration: Save the file, then restart the ETCD service to apply the configuration changes. systemctl restart etcd To verify the ETCD status, run: systemctl status etcd Output: Next, you will need to create a patroni.yml file on both node1 and node2. On node1, create a new patroni.yml file: nano \/etc\/patroni.yml Add the following configuration: Save the file, then create a data directory for Patroni and set proper ownership on node1: On node2, create a new patroni.yml file: nano \/etc\/patroni.yml Add the following configuration: Save the file, then create a data directory for Patroni and set proper ownership on node2: Next, create a systemd unit file for managing Patroni service on node1 and node2: nano \/etc\/systemd\/system\/patroni.service Add the following configuration: Save the file, then reload the systemd daemon: systemctl daemon-reload Next, start the Patroni and PostgreSQL service on both node1 and node2: To verify the status of Patroni, run: systemctl status patroni Output: Next, edit the HAProxy main configuration file on node4: nano \/etc\/haproxy\/haproxy.cfg Remove default configuration and add the following configuration: Save the file, then restart the HAProxy service to apply the changes: systemctl restart haproxy To verify the status of HAProxy, run: systemctl status haproxy Output: You can now access the PostgreSQL cluster using the HAProxy IP address. To do so, open your web browser and type the URL http:\/\/45.58.47.24:7000. You should see your cluster status on the following screen: As you can see, the row highlighted in green is acting as a master, and the row highlighted in red is acting as a slave. Congratulations! you have successfully deployed a four-node Patroni cluster on Ubuntu 20.04 server. However, it is recommended to add more etcd nodes to improve availability and add an HAProxy server for IP failover. Published at DZone with permission of Everett Berry. See the original article here. Opinions expressed by DZone contributors are their own.<\/p>\n<script>jQuery(function(){jQuery(\".vc_icon_element-icon\").css(\"top\", \"0px\");});<\/script><script>jQuery(function(){jQuery(\"#td_post_ranks\").css(\"height\", \"10px\");});<\/script><script>jQuery(function(){jQuery(\".td-post-content\").find(\"p\").find(\"img\").hide();});<\/script>","protected":false},"excerpt":{"rendered":"<p>This guide demonstrates how you can create a PostgreSQL High Availability cluster with Patroni, etcd, and HAProxy on Ubuntu 20.04. Join the DZone community and get the full member experience. PostgreSQL is an open-source, versatile, and most popular database system around the world. However, it does not have any features for high availability. Enter Patroni. [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":1967947,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":[],"categories":[93],"tags":[],"_links":{"self":[{"href":"http:\/\/nhub.news\/ru\/wp-json\/wp\/v2\/posts\/1967948"}],"collection":[{"href":"http:\/\/nhub.news\/ru\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/nhub.news\/ru\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/nhub.news\/ru\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/nhub.news\/ru\/wp-json\/wp\/v2\/comments?post=1967948"}],"version-history":[{"count":1,"href":"http:\/\/nhub.news\/ru\/wp-json\/wp\/v2\/posts\/1967948\/revisions"}],"predecessor-version":[{"id":1967949,"href":"http:\/\/nhub.news\/ru\/wp-json\/wp\/v2\/posts\/1967948\/revisions\/1967949"}],"wp:featuredmedia":[{"embeddable":true,"href":"http:\/\/nhub.news\/ru\/wp-json\/wp\/v2\/media\/1967947"}],"wp:attachment":[{"href":"http:\/\/nhub.news\/ru\/wp-json\/wp\/v2\/media?parent=1967948"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/nhub.news\/ru\/wp-json\/wp\/v2\/categories?post=1967948"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/nhub.news\/ru\/wp-json\/wp\/v2\/tags?post=1967948"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}