Skip to content

PostgreSQL cluster implementation featuring automatic failover and replication using Docker Compose. This setup ensures continuous database availability through master-slave replication and automated failover mechanisms.

Notifications You must be signed in to change notification settings

pawarspeaks/postgresql-cluster

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1 Commit
 
 
 
 
 
 
 
 
 
 

Repository files navigation

PostgreSQL Replication with Docker

A hands-on implementation of PostgreSQL database replication using Docker, demonstrating high availability through master-slave configuration. This project showcases database replication, failover scenarios, and container orchestration skills using Docker Compose.

Overview

This project implements:

  • Primary-Standby PostgreSQL replication
  • Write-Ahead Logging (WAL) configuration
  • Automated container orchestration
  • Data persistence across container restarts
  • Basic failover handling

Prerequisites

  • Docker Engine
  • Docker Compose
  • Git

Project Structure

├── docker-compose.yml
├── postgres-1/
│   └── config/
│       ├── postgresql.conf
│       └── pg_hba.conf
└── postgres-2/
    └── config/
        ├── postgresql.conf
        └── pg_hba.conf

Quick Start

  1. Clone the repository:
git clone https://github.com/pawarspeaks/postgresql-cluster.git
cd postgresql-cluster
  1. Launch the cluster:
docker-compose up -d
  1. Verify cluster status:
docker-compose ps

Testing Replication

  1. Connect to primary node:
docker exec -it postgres-1 psql -U postgres
  1. Check replication status:
SELECT * FROM pg_stat_replication;

Testing Failover

  1. Simulate primary node failure:
docker-compose stop postgres-1
  1. Verify secondary node status:
docker exec -it postgres-2 psql -U postgres -c "SELECT pg_is_in_recovery();"

Configuration Details

Key configuration files:

  • postgresql.conf: Contains replication settings like WAL configuration
  • pg_hba.conf: Manages host-based authentication for replication
  • docker-compose.yml: Orchestrates the PostgreSQL containers

Author

@Pawarspeaks

About

PostgreSQL cluster implementation featuring automatic failover and replication using Docker Compose. This setup ensures continuous database availability through master-slave replication and automated failover mechanisms.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published