For enterprise applications, SaaS platforms, and large e-commerce sites, a database outage means catastrophic revenue loss. Relying on a single database server is a single point of failure.
To ensure true 100% uptime, you need a PostgreSQL High Availability (HA) Cluster. In this architecture, multiple database servers run in sync. If the primary master server crashes, the system automatically detects the failure and promotes a standby server to take over in seconds, with zero manual intervention.
This tutorial covers setting up a robust PostgreSQL HA cluster on Ubuntu 24.04 bare-metal servers using Patroni (for failover management), etcd (for distributed consensus), and HAProxy (for routing client traffic).
Step 1: Architecture & Prerequisites
To prevent a "split-brain" scenario where two servers both think they are the primary, a highly available cluster requires an odd number of nodes to maintain a quorum. Therefore, this setup requires three bare-metal servers.
- Node 1 (db1): 10.0.0.11
- Node 2 (db2): 10.0.0.12
- Node 3 (db3): 10.0.0.13
Step 3: Install PostgreSQL & Dependencies
On all three nodes, install PostgreSQL, Python3, and etcd:
bash
apt install -y postgresql postgresql-contrib python3-pip python3-venv etcd curl
Top comments (0)