The final element on the stack is HAProxy. Patroni uses this to redirect traffic to the primary read/write node in our PostgreSQL cluster. Technically we don't strictly need this component since Patroni will operate without it. But if we want the capability to always reach the primary node regardless of its location, this recipe is essential.
Let's build a high availability connection proxy!
This recipe depends on some necessary libraries and services. Please follow the Preparing systems for the stack and Installing and configuring Patroni recipes before continuing.
If this is a Debian-based system, begin by installing HAProxy from the standard system repository with this apt-get
command:
sudo apt-get install haproxy
For Red-Hat-based servers, use an equivalent yum
command:
yum install haproxy