PostgreSQL HA Cluster with Patroni, etcd, and HAProxy
Advanced · 60 minutes · 100 points
Build a production-grade three-node PostgreSQL cluster managed by Patroni with etcd as the distributed configuration store, all orchestrated via Docker Compose inside a single container. You will simulate leader failure, observe automatic failover, and route client connections through HAProxy for seamless reconnection. This lab covers the full lifecycle of a high-availability database setup used in real-world production environments.
What you’ll learn
- Install Docker Compose and all required tooling inside the lab container
- Write a complete Docker Compose stack defining etcd, three Patroni-managed PostgreSQL nodes, and HAProxy
- Configure Patroni YAML files for each node with correct etcd integration and replication settings
- Configure HAProxy to route writes to the Patroni leader and reads to replicas
- Simulate a leader failure by killing the leader container and verify automatic failover promotes a replica
- Reconnect a psql client through HAProxy after failover and confirm writes succeed on the new leader
How this lab works
- Start the lab: One click starts a container on your computer with a real terminal: nothing to install by hand, nothing to clean up.
- Work through 6 tasks: Each task says what to build or fix. You do it yourself, in a real terminal, with hints when you get stuck.
- Check your work: Check my work runs each task’s checks in your container and says what passed and what to fix.
- Finish and keep going: 100 points, your progress saved, and the next lab to try.
What it runs on
- Runs: A container on your computer, with a real terminal
- Image: ubuntu:22.04
What you need
- A free LearnXops account
- The LearnXops desktop app for macOS, Windows or Linux
- Docker Desktop installed and running
- At least 4GB RAM available
- At least 4GB free disk space
Topics: postgresql, patroni, etcd, haproxy, high-availability, failover, docker-compose, replication, databases, production
Create a free account to start this lab.