This project provides a complete setup for a PostgreSQL High Availability (HA) cluster using Patroni, etcd, and HAProxy, all running in Docker containers.
- docker-compose.yml: Defines the services, networks, and volumes for the Docker containers.
- patroni/: Contains the configuration and Dockerfile for the Patroni service.
- patroni.yml: Configuration settings for Patroni, including PostgreSQL and etcd connection details.
- Dockerfile: Builds the Docker image for the Patroni service.
- etcd/: Contains the configuration for the etcd service.
- etcd.conf: Configuration settings for etcd, including cluster settings and data storage options.
- haproxy/: Contains the configuration and Dockerfile for the HAProxy service.
- haproxy.cfg: Configuration settings for HAProxy, including frontend and backend definitions.
- Dockerfile: Builds the Docker image for the HAProxy service.
- scripts/: Contains scripts for initializing the cluster and performing health checks.
- init-cluster.sh: Initializes the PostgreSQL cluster using Patroni.
- health-check.sh: Performs health checks on the PostgreSQL nodes.
- .env: Contains environment variables used in the Docker containers.
- README.md: Documentation for the project.
-
Clone the Repository: Clone this repository to your local machine.
-
Configure Environment Variables: Update the
.envfile with your database credentials and service configurations. -
Build and Start the Services: Run the following command to build and start the Docker containers:
docker-compose up -d -
Initialize the Cluster: Execute the initialization script to set up the PostgreSQL cluster:
./scripts/init-cluster.sh -
Health Check: Use the health check script to ensure all PostgreSQL nodes are running:
./scripts/health-check.sh
- Access the PostgreSQL database through HAProxy for load balancing.
- Monitor the logs of each service for troubleshooting and performance tuning.
- Modify the configuration files as needed to suit your specific requirements.
For more details on each component, refer to their respective documentation:
This setup aims to provide a robust and scalable PostgreSQL HA solution suitable for production environments.
