Skip to content

2SSK/postgres-ha-cluster

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

3 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Postgres High Availability Setup with Patroni, etcd, and HAProxy

This project provides a complete setup for a PostgreSQL High Availability (HA) cluster using Patroni, etcd, and HAProxy, all running in Docker containers.

Demo

Demo

Project Structure

  • 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.

Setup Instructions

  1. Clone the Repository: Clone this repository to your local machine.

  2. Configure Environment Variables: Update the .env file with your database credentials and service configurations.

  3. Build and Start the Services: Run the following command to build and start the Docker containers:

    docker-compose up -d
    
  4. Initialize the Cluster: Execute the initialization script to set up the PostgreSQL cluster:

    ./scripts/init-cluster.sh
    
  5. Health Check: Use the health check script to ensure all PostgreSQL nodes are running:

    ./scripts/health-check.sh
    

Usage Guidelines

  • 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.

Additional Information

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.

About

Postgres HA setup with Patroni, HAProxy and etcd

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published