<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>ha Archives - ServerStadium</title>
	<atom:link href="https://serverstadium.com/knowledge-base/tag/ha/feed/" rel="self" type="application/rss+xml" />
	<link>https://serverstadium.com/knowledge-base/tag/ha/</link>
	<description>Public Cloud Solution by ServerStadium</description>
	<lastBuildDate>Fri, 14 Apr 2023 07:03:54 +0000</lastBuildDate>
	<language>en-US</language>
	<sy:updatePeriod>
	hourly	</sy:updatePeriod>
	<sy:updateFrequency>
	1	</sy:updateFrequency>
	<generator>https://wordpress.org/?v=7.1.4</generator>

<image>
	<url>https://serverstadium.com/wp-content/uploads/2023/04/cropped-favicon-1-32x32.png</url>
	<title>ha Archives - ServerStadium</title>
	<link>https://serverstadium.com/knowledge-base/tag/ha/</link>
	<width>32</width>
	<height>32</height>
</image> 
	<item>
		<title>Set Up High Availability PostgreSQL Cluster Using Patroni on ServerStadium</title>
		<link>https://serverstadium.com/knowledge-base/set-up-high-availability-postgresql-cluster-using-patroni-on-serverstadium/</link>
		
		<dc:creator><![CDATA[Brian K]]></dc:creator>
		<pubDate>Wed, 06 Jul 2022 07:40:20 +0000</pubDate>
				<guid isPermaLink="false">https://cloudraya.com/knowledge-base/?p=2096</guid>

					<description><![CDATA[<p>PostgreSQL is a powerful OpenSource, an object-relational database management system that extends the SQL language with many features. Meanwhile, Patroni is an OpenSource python package that we can use to manage and automate the deployment of PostgreSQL HA Clusters. Little information, Patroni was developed by Zalando. Prerequisite To follow this tutorial, we need three VM&#8230;</p>
<p>The post <a href="https://serverstadium.com/knowledge-base/set-up-high-availability-postgresql-cluster-using-patroni-on-serverstadium/">Set Up High Availability PostgreSQL Cluster Using Patroni on ServerStadium</a> appeared first on <a href="https://serverstadium.com">ServerStadium</a>.</p>
]]></description>
										<content:encoded><![CDATA[
<p class="wp-block-paragraph">PostgreSQL is a powerful OpenSource, an object-relational database management system that extends the SQL language with many features.</p>



<p class="wp-block-paragraph">Meanwhile, Patroni is an OpenSource python package that we can use to manage and automate the deployment of PostgreSQL HA Clusters. Little information, Patroni was developed by Zalando.</p>



<h2 class="has-vivid-cyan-blue-color has-text-color wp-block-heading"><strong>Prerequisite</strong></h2>



<p class="wp-block-paragraph">To follow this tutorial, we need three VM for PostgreSQL and one VM for HAproxy and etcd.<br>Below is four VMs that we will deploy in ServerStadium.</p>



<div class="wp-block-columns is-layout-flex wp-container-core-columns-is-layout-8f761849 wp-block-columns-is-layout-flex">
<div class="wp-block-column is-layout-flow wp-block-column-is-layout-flow" style="flex-basis:100%">
<figure class="wp-block-table"><table><tbody><tr><td class="has-text-align-center" data-align="center"><strong>Hostname</strong></td><td class="has-text-align-center" data-align="center"><strong>IP Address</strong></td><td class="has-text-align-left" data-align="left"><strong>Applications</strong></td></tr><tr><td class="has-text-align-center" data-align="center">haetcd</td><td class="has-text-align-center" data-align="center">199.180.130.99</td><td class="has-text-align-left" data-align="left">HAproxy</td></tr><tr><td class="has-text-align-center" data-align="center"></td><td class="has-text-align-center" data-align="center">10.3.3.166</td><td class="has-text-align-left" data-align="left">etcd</td></tr><tr><td class="has-text-align-center" data-align="center">pgsql1</td><td class="has-text-align-center" data-align="center">10.3.3.12</td><td class="has-text-align-left" data-align="left">patroni</td></tr><tr><td class="has-text-align-center" data-align="center">pgsql2</td><td class="has-text-align-center" data-align="center">10.3.3.71</td><td class="has-text-align-left" data-align="left">patroni</td></tr><tr><td class="has-text-align-center" data-align="center">pgsql3</td><td class="has-text-align-center" data-align="center">10.3.3.70</td><td class="has-text-align-left" data-align="left">patroni</td></tr></tbody></table></figure>
</div>
</div>



<p class="wp-block-paragraph">We will use haetcd as jumpbox server since the VM has Public IP Address that we can access from the outside network. In /etc/host, insert the hostname of the servers to make us easy to access the server without remembering the IP Address.</p>



<p class="wp-block-paragraph">/etc/hosts</p>



<figure class="wp-block-image size-full"><img decoding="async" width="284" height="144" src="https://serverstadium.com/wp-content/uploads/2022/05/image.png" alt="" class="wp-image-2098"/></figure>



<h2 class="has-vivid-cyan-blue-color has-text-color wp-block-heading"><strong>Install PostgreSQL 14</strong></h2>



<p class="wp-block-paragraph">In this step, we will use PostgreSQL14 for pgsql1, pgsql2, and pgsql3. Please the command below on each server.</p>



<pre class="wp-block-preformatted"><code>sh -c 'echo "deb http://apt.postgresql.org/pub/repos/apt $(lsb_release -cs)-pgdg main" &gt; /etc/apt/sources.list.d/pgdg.list'</code>
<code>
wget --quiet -O - https://www.postgresql.org/media/keys/ACCC4CF8.asc | sudo apt-key add -

apt update</code></pre>



<figure class="wp-block-image size-full"><img fetchpriority="high" decoding="async" width="1157" height="260" src="https://serverstadium.com/wp-content/uploads/2022/05/image-2.png" alt="" class="wp-image-2100" srcset="https://serverstadium.com/wp-content/uploads/2022/05/image-2.png 1157w, https://serverstadium.com/wp-content/uploads/2022/05/image-2-300x67.png 300w, https://serverstadium.com/wp-content/uploads/2022/05/image-2-1024x230.png 1024w, https://serverstadium.com/wp-content/uploads/2022/05/image-2-768x173.png 768w" sizes="(max-width: 1157px) 100vw, 1157px" /></figure>



<pre class="wp-block-preformatted">apt -y install postgresql-14 postgresql-server-dev-14</pre>



<figure class="wp-block-image size-full"><img decoding="async" width="1157" height="131" src="https://serverstadium.com/wp-content/uploads/2022/05/image-3.png" alt="" class="wp-image-2101" srcset="https://serverstadium.com/wp-content/uploads/2022/05/image-3.png 1157w, https://serverstadium.com/wp-content/uploads/2022/05/image-3-300x34.png 300w, https://serverstadium.com/wp-content/uploads/2022/05/image-3-1024x116.png 1024w, https://serverstadium.com/wp-content/uploads/2022/05/image-3-768x87.png 768w" sizes="(max-width: 1157px) 100vw, 1157px" /></figure>



<p class="wp-block-paragraph">After the postgresql installation is completed, we need to stop and disable PostgreSQL service. Then we will continue to install patroni.</p>



<p class="wp-block-paragraph"> <code>systemctl stop postgresql &amp;&amp; systemctl disable postgresql</code></p>



<h2 class="has-vivid-cyan-blue-color has-text-color wp-block-heading"><strong>Install Patroni</strong></h2>



<p class="wp-block-paragraph">Patroni uses the utilities of PostgreSQL that we have installed previously which is located at <strong>/usr/lib/postgresql/versin/bin </strong>directory.</p>



<p class="wp-block-paragraph">In this step, we create a symbolic link to PostgreSQL utilities on psql1, psql2, and psql3 </p>



<p class="wp-block-paragraph"><code>ln -s /usr/lib/postgresql/14/bin/* /usr/sbin/ </code></p>



<p class="wp-block-paragraph">Next, we will install patroni on each server</p>



<p class="wp-block-paragraph"><code>apt -y install python3 python3-pip <br>pip install --upgrade setuptools <br>pip install psycopg2 <br>pip install patroni <br>pip install python-etcd</code></p>



<figure class="wp-block-image size-full"><img loading="lazy" decoding="async" width="1157" height="340" src="https://serverstadium.com/wp-content/uploads/2022/05/image-4.png" alt="" class="wp-image-2102" srcset="https://serverstadium.com/wp-content/uploads/2022/05/image-4.png 1157w, https://serverstadium.com/wp-content/uploads/2022/05/image-4-300x88.png 300w, https://serverstadium.com/wp-content/uploads/2022/05/image-4-1024x301.png 1024w, https://serverstadium.com/wp-content/uploads/2022/05/image-4-768x226.png 768w" sizes="(max-width: 1157px) 100vw, 1157px" /></figure>



<p class="wp-block-paragraph"></p>



<h2 class="has-vivid-cyan-blue-color has-text-color wp-block-heading"><strong>Configure Patroni on Pgsql1, Pgsql2, and Pgsql3</strong></h2>



<p class="wp-block-paragraph">Patroni uses yaml files to store the configuration. We will place the yaml file on /etc directory. </p>



<pre class="wp-block-preformatted">sudo nano /etc/patroni.yml

<strong>pgsql1:</strong>
scope: postgres
namespace: /db/
name: <strong>pgsql1</strong>

restapi:
    listen: <strong>10.3.3.12</strong>:8008
    connect_address: <strong>10.3.3.12</strong>:8008

etcd:
    host:  <strong>10.3.3.166</strong>:2379

bootstrap:
    dcs:
        ttl: 30
        loop_wait: 10
        retry_timeout: 10
        maximum_lag_on_failover: 1048576
        postgresql:
            use_pg_rewind: true

    initdb:
    - encoding: UTF8
    - data-checksums

    pg_hba:
    - host replication replicator 127.0.0.1/32 md5
    - host replication replicator 10.3.3.12/0 md5
    - host replication replicator 10.3.3.71/0 md5
    - host replication replicator 10.3.3.70/0 md5
    - host all all 0.0.0.0/0 md5

    users:
        admin:
            password: admin
            options:
                - createrole
                - createdb

postgresql:
    listen: <strong>10.3.3.12</strong>:5432
    connect_address: <strong>10.3.3.12</strong>:5432
    data_dir: /data/patroni
    pgpass: /tmp/pgpass
    authentication:
        replication:
            username: replicator
            password: replogin321
        superuser:
            username: postgres
            password: secretlogin321
    parameters:
        unix_socket_directories: '.'

tags:
    nofailover: false
    noloadbalance: false
    clonefrom: false
    nosync: false

<strong>pgsql2</strong>
scope: postgres
namespace: /db/
name: <strong>pgsql2</strong>

restapi:
    listen: <strong>10.3.3.71</strong>:8008
    connect_address: <strong>10.3.3.71</strong>:8008

etcd:
    host:  <strong>10.3.3.166</strong>:2379

bootstrap:
    dcs:
        ttl: 30
        loop_wait: 10
        retry_timeout: 10
        maximum_lag_on_failover: 1048576
        postgresql:
            use_pg_rewind: true

    initdb:
    - encoding: UTF8
    - data-checksums

    pg_hba:
    - host replication replicator 127.0.0.1/32 md5
    - host replication replicator 10.3.3.12/0 md5
    - host replication replicator 10.3.3.71/0 md5
    - host replication replicator 10.3.3.70/0 md5
    - host all all 0.0.0.0/0 md5

    users:
        admin:
            password: admin
            options:
                - createrole
                - createdb

postgresql:
    listen: <strong>10.3.3.71</strong>:5432
    connect_address: <strong>10.3.3.71</strong>:5432
    data_dir: /data/patroni
    pgpass: /tmp/pgpass
    authentication:
        replication:
            username: replicator
            password: replogin321
        superuser:
            username: postgres
            password: secretlogin321
    parameters:
        unix_socket_directories: '.'

tags:
    nofailover: false
    noloadbalance: false
    clonefrom: false
    nosync: false

<strong>pgsql3
</strong>scope: postgres
namespace: /db/
name: <strong>pgsql3</strong>

restapi:
    listen: <strong>10.3.3.70</strong>:8008
    connect_address: <strong>10.3.3.70</strong>:8008

etcd:
    host:  10.3.3.166:2379

bootstrap:
    dcs:
        ttl: 30
        loop_wait: 10
        retry_timeout: 10
        maximum_lag_on_failover: 1048576
        postgresql:
            use_pg_rewind: true

    initdb:
    - encoding: UTF8
    - data-checksums

    pg_hba:
    - host replication replicator 127.0.0.1/32 md5
    - host replication replicator 10.3.3.12/0 md5
    - host replication replicator 10.3.3.71/0 md5
    - host replication replicator 10.3.3.70/0 md5
    - host all all 0.0.0.0/0 md5

    users:
        admin:
            password: admin
            options:
                - createrole
                - createdb

postgresql:
    listen: <strong>10.3.3.70</strong>:5432
    connect_address: <strong>10.3.3.70</strong>:5432
    data_dir: /data/patroni
    pgpass: /tmp/pgpass
    authentication:
        replication:
            username: replicator
            password: replogin321
        superuser:
            username: postgres
            password: secretlogin321
    parameters:
        unix_socket_directories: '.'

tags:
    nofailover: false
    noloadbalance: false
    clonefrom: false
    nosync: false
</pre>



<p class="wp-block-paragraph">According to the yml file, the data of PostgreSQL will be stored at /data/patroni. Make sure the ownership of that directory is postgres.</p>



<p class="wp-block-paragraph"><code>mkdir -p /data/patroni</code><br>chown postgres:postgres /data/patroni<br><code>chmod 700 /data/patroni</code></p>



<h2 class="has-vivid-cyan-blue-color has-text-color wp-block-heading"><strong>Create a Service</strong></h2>



<p class="wp-block-paragraph">Next, we will create patroni service that allow us to start and stop the service on each server.</p>



<p class="wp-block-paragraph"><code>sudo nano /etc/systemd/system/patroni.service</code></p>



<p class="wp-block-paragraph">Add the following parameter in the patroni.service<code><br>[Unit]<br>Description=High availability PostgreSQL Cluster<br>After=syslog.target network.target<br>[Service]<br>Type=simple<br>User=postgres<br>Group=postgres<br>ExecStart=/usr/local/bin/patroni /etc/patroni.yml<br>KillMode=process<br>TimeoutSec=30<br>Restart=no<br><br>[Install]<br>WantedBy=multi-user.target</code></p>



<h2 class="has-vivid-cyan-blue-color has-text-color wp-block-heading"><strong>Create and Enable Patroni Service</strong></h2>



<p class="wp-block-paragraph">After the patroni service has been created then we enable it to make it autostart.</p>



<p class="wp-block-paragraph"><code>sudo systemctl daemon-reload<br>sudo systemctl enable patroni</code></p>



<h2 class="has-vivid-cyan-blue-color has-text-color wp-block-heading"><strong>Install Etcd and Haproxy</strong> <strong>on Haetcd VM</strong></h2>



<p class="wp-block-paragraph">etcd is a fault-tolerant, a distributed key value store that can be used to store the state of PostgreSQL cluster.  With etcd, it will keep the PostgreSQL cluster up and running.</p>



<p class="wp-block-paragraph">Run the command below to install etcd</p>



<pre class="wp-block-preformatted">sudo apt -y install etcd</pre>



<figure class="wp-block-image size-full"><img loading="lazy" decoding="async" width="1157" height="156" src="https://serverstadium.com/wp-content/uploads/2022/05/image-5.png" alt="" class="wp-image-2104" srcset="https://serverstadium.com/wp-content/uploads/2022/05/image-5.png 1157w, https://serverstadium.com/wp-content/uploads/2022/05/image-5-300x40.png 300w, https://serverstadium.com/wp-content/uploads/2022/05/image-5-1024x138.png 1024w, https://serverstadium.com/wp-content/uploads/2022/05/image-5-768x104.png 768w" sizes="(max-width: 1157px) 100vw, 1157px" /></figure>



<p class="wp-block-paragraph">Next step, we will configure the etcd file. Add the below parameter in the etcd file:</p>



<p class="wp-block-paragraph"><code>sudo nano /etc/default/etcd</code></p>



<p class="wp-block-paragraph"><code>ETCD_LISTEN_PEER_URLS="http://<strong>10.3.3.166</strong>:2380"<br>ETCD_LISTEN_CLIENT_URLS="http://localhost:2379,http://<strong>10.3.3.166</strong>:2379"<br>ETCD_INITIAL_ADVERTISE_PEER_URLS="http://<strong>10.3.3.166</strong>:2380"<br>ETCD_INITIAL_CLUSTER="default=http://<strong>10.3.3.166</strong>:2380"<br>ETCD_ADVERTISE_CLIENT_URLS="http://<strong>10.3.3.166</strong>:2379"<br>ETCD_INITIAL_CLUSTER_TOKEN="etcd-cluster"<br>ETCD_INITIAL_CLUSTER_STATE="new"</code><br></p>



<p class="wp-block-paragraph">Restart the etcd service to make a change effect</p>



<p class="wp-block-paragraph"><code>sudo systemctl restart etcd<br></code></p>



<h2 class="has-vivid-cyan-blue-color has-text-color wp-block-heading"><strong>Start Patroni on Each Pgsql Server</strong></h2>



<p class="wp-block-paragraph">Before we start the patroni service, we need to activate the watchdog support to prevent split-brain on the PostgreSQL<br><br>https://patroni.readthedocs.io/en/latest/watchdog.html<br><br><code>modprobe softdog<br>chown postgres /dev/watchdog</code></p>



<figure class="wp-block-image size-full"><img loading="lazy" decoding="async" width="705" height="56" src="https://serverstadium.com/wp-content/uploads/2022/05/image-6.png" alt="" class="wp-image-2105" srcset="https://serverstadium.com/wp-content/uploads/2022/05/image-6.png 705w, https://serverstadium.com/wp-content/uploads/2022/05/image-6-300x24.png 300w" sizes="(max-width: 705px) 100vw, 705px" /></figure>



<p class="wp-block-paragraph">After the watchdog is activated, now we can start the patroni service again on each server.</p>



<p class="wp-block-paragraph"><code>systemctl start patroni</code><br><code>systemctl status patroni</code></p>



<p class="wp-block-paragraph">pgsql1 as master. <br>We can see, the pgsql1 will act as the PostgreSQL master</p>



<figure class="wp-block-image size-full"><img loading="lazy" decoding="async" width="1157" height="372" src="https://serverstadium.com/wp-content/uploads/2022/05/image-7.png" alt="" class="wp-image-2106" srcset="https://serverstadium.com/wp-content/uploads/2022/05/image-7.png 1157w, https://serverstadium.com/wp-content/uploads/2022/05/image-7-300x96.png 300w, https://serverstadium.com/wp-content/uploads/2022/05/image-7-1024x329.png 1024w, https://serverstadium.com/wp-content/uploads/2022/05/image-7-768x247.png 768w" sizes="(max-width: 1157px) 100vw, 1157px" /></figure>



<p class="wp-block-paragraph">pgsql2 and pgsql3 as slave</p>



<figure class="wp-block-image size-full"><img loading="lazy" decoding="async" width="1157" height="366" src="https://serverstadium.com/wp-content/uploads/2022/05/image-8.png" alt="" class="wp-image-2107" srcset="https://serverstadium.com/wp-content/uploads/2022/05/image-8.png 1157w, https://serverstadium.com/wp-content/uploads/2022/05/image-8-300x95.png 300w, https://serverstadium.com/wp-content/uploads/2022/05/image-8-1024x324.png 1024w, https://serverstadium.com/wp-content/uploads/2022/05/image-8-768x243.png 768w" sizes="(max-width: 1157px) 100vw, 1157px" /></figure>



<figure class="wp-block-image size-full"><img loading="lazy" decoding="async" width="1157" height="353" src="https://serverstadium.com/wp-content/uploads/2022/05/image-9.png" alt="" class="wp-image-2108" srcset="https://serverstadium.com/wp-content/uploads/2022/05/image-9.png 1157w, https://serverstadium.com/wp-content/uploads/2022/05/image-9-300x92.png 300w, https://serverstadium.com/wp-content/uploads/2022/05/image-9-1024x312.png 1024w, https://serverstadium.com/wp-content/uploads/2022/05/image-9-768x234.png 768w" sizes="(max-width: 1157px) 100vw, 1157px" /></figure>



<h2 class="has-vivid-cyan-blue-color has-text-color wp-block-heading"><strong>Install Haproxy</strong></h2>



<p class="wp-block-paragraph">Our last step install HAproxy service to give us an endpoint to which the application can connect to the database.</p>



<p class="wp-block-paragraph"><code>sudo apt -y install haproxy</code></p>



<figure class="wp-block-image size-full"><img loading="lazy" decoding="async" width="1157" height="146" src="https://serverstadium.com/wp-content/uploads/2022/05/image-10.png" alt="" class="wp-image-2109" srcset="https://serverstadium.com/wp-content/uploads/2022/05/image-10.png 1157w, https://serverstadium.com/wp-content/uploads/2022/05/image-10-300x38.png 300w, https://serverstadium.com/wp-content/uploads/2022/05/image-10-1024x129.png 1024w, https://serverstadium.com/wp-content/uploads/2022/05/image-10-768x97.png 768w" sizes="(max-width: 1157px) 100vw, 1157px" /></figure>



<p class="wp-block-paragraph" id="block-afeeab82-1a19-4d69-a234-c7d500db5846">Edit the haproxy file configuration as follow</p>



<pre class="wp-block-preformatted"><code>nano /etc/haproxy/haproxy.cfg</code>
global
    maxconn 100

defaults
    log global
    mode tcp
    retries 2
    timeout client 30m
    timeout connect 4s
    timeout server 30m
    timeout check 5s

listen stats
    mode http
    bind *:7000
    stats enable
    stats uri /

listen postgres
    bind *:5000
    option httpchk
    http-check expect status 200
    default-server inter 3s fall 3 rise 2 on-marked-down shutdown-sessions
    server pgsql1 <strong>10.3.3.12</strong>:5432 maxconn 100 check port 8008
    server pgsql2 <strong>10.3.3.71</strong>:5432 maxconn 100 check port 8008
    server pgsql3 <strong>10.3.3.70</strong>:5432 maxconn 100 check port 8008
</pre>



<p class="wp-block-paragraph">Check our haproxy configuration using the following command:</p>



<pre class="wp-block-preformatted">sudo /usr/sbin/haproxy -c -V -f /etc/haproxy/haproxy.cfg&nbsp;</pre>



<figure class="wp-block-image size-full"><img loading="lazy" decoding="async" width="1000" height="54" src="https://serverstadium.com/wp-content/uploads/2022/05/image-11.png" alt="" class="wp-image-2110" srcset="https://serverstadium.com/wp-content/uploads/2022/05/image-11.png 1000w, https://serverstadium.com/wp-content/uploads/2022/05/image-11-300x16.png 300w, https://serverstadium.com/wp-content/uploads/2022/05/image-11-768x41.png 768w" sizes="(max-width: 1000px) 100vw, 1000px" /></figure>



<p class="wp-block-paragraph">If the configuration is valid, we can restart our haproxy service</p>



<p class="wp-block-paragraph"><code>sudo systemctl restart haproxy</code></p>



<figure class="wp-block-image size-full"><img loading="lazy" decoding="async" width="1157" height="307" src="https://serverstadium.com/wp-content/uploads/2022/05/image-12.png" alt="" class="wp-image-2111" srcset="https://serverstadium.com/wp-content/uploads/2022/05/image-12.png 1157w, https://serverstadium.com/wp-content/uploads/2022/05/image-12-300x80.png 300w, https://serverstadium.com/wp-content/uploads/2022/05/image-12-1024x272.png 1024w, https://serverstadium.com/wp-content/uploads/2022/05/image-12-768x204.png 768w" sizes="(max-width: 1157px) 100vw, 1157px" /></figure>



<p class="wp-block-paragraph"></p>



<p class="wp-block-paragraph">In the final step, we can monitor the PostgreSQL cluster using the browser as shown in the screenshot below:</p>



<p class="wp-block-paragraph"><a href="http://199.180.130.99:7000/">http://199.180.130.99:7000/</a></p>



<figure class="wp-block-image size-full"><img loading="lazy" decoding="async" width="1157" height="380" src="https://serverstadium.com/wp-content/uploads/2022/05/image-13.png" alt="" class="wp-image-2112" srcset="https://serverstadium.com/wp-content/uploads/2022/05/image-13.png 1157w, https://serverstadium.com/wp-content/uploads/2022/05/image-13-300x99.png 300w, https://serverstadium.com/wp-content/uploads/2022/05/image-13-1024x336.png 1024w, https://serverstadium.com/wp-content/uploads/2022/05/image-13-768x252.png 768w" sizes="(max-width: 1157px) 100vw, 1157px" /></figure>



<p class="wp-block-paragraph">As we can see, psql1 is the leader of the PostgreSQL cluster with the green line row.<br>Now we will kill patroni service on psql1, to see which VM will be acting as the leader.</p>



<p class="wp-block-paragraph"><code>systemctl stop patroni</code></p>



<figure class="wp-block-image size-full"><img loading="lazy" decoding="async" width="1157" height="374" src="https://serverstadium.com/wp-content/uploads/2022/05/image-14.png" alt="" class="wp-image-2113" srcset="https://serverstadium.com/wp-content/uploads/2022/05/image-14.png 1157w, https://serverstadium.com/wp-content/uploads/2022/05/image-14-300x97.png 300w, https://serverstadium.com/wp-content/uploads/2022/05/image-14-1024x331.png 1024w, https://serverstadium.com/wp-content/uploads/2022/05/image-14-768x248.png 768w" sizes="(max-width: 1157px) 100vw, 1157px" /></figure>



<p class="wp-block-paragraph">After we stop service patroni service in psql1, the psql2 will be elected as the leader node.</p>



<h2 class="has-vivid-cyan-blue-color has-text-color wp-block-heading"><br><strong>Test PostgresSQL Cluster</strong></h2>



<p class="wp-block-paragraph">If we want to make a connection to PostgreSQL, we use the IP Address of HAProxy and port 5000.</p>



<p class="wp-block-paragraph"><code>su - postgres<br>psql -U postgres -h 199.180.130.99 -p 5000</code></p>



<figure class="wp-block-image size-full"><img loading="lazy" decoding="async" width="550" height="96" src="https://serverstadium.com/wp-content/uploads/2022/05/image-15.png" alt="" class="wp-image-2120" srcset="https://serverstadium.com/wp-content/uploads/2022/05/image-15.png 550w, https://serverstadium.com/wp-content/uploads/2022/05/image-15-300x52.png 300w" sizes="(max-width: 550px) 100vw, 550px" /></figure>



<p class="wp-block-paragraph"><br>You now have a high availability PostgreSQL Cluster in ServerStadium that is ready to use.<br>Please don&#8217;t hesitate to <a href="https://serverstadium.com/id/contact/" target="_blank" rel="noreferrer noopener">contact ServerStadium support</a> if you need further assistance.</p>



<p class="wp-block-paragraph">Find more tutorials articles about ServerStadium in our Knowledge Base, or if you want to get more general knowledge about technology feel free to visit our <a href="https://serverstadium.com/blog/" target="_blank" rel="noreferrer noopener">Blog.</a> </p>



<p class="wp-block-paragraph">Curious to know more about our products and panel? register <a href="https://cp.serverstadium.com/regist-user" target="_blank" rel="noreferrer noopener">here</a> for free!.</p>
<p>The post <a href="https://serverstadium.com/knowledge-base/set-up-high-availability-postgresql-cluster-using-patroni-on-serverstadium/">Set Up High Availability PostgreSQL Cluster Using Patroni on ServerStadium</a> appeared first on <a href="https://serverstadium.com">ServerStadium</a>.</p>
]]></content:encoded>
					
		
		
			</item>
	</channel>
</rss>
