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.
This project implements:
- Primary-Standby PostgreSQL replication
- Write-Ahead Logging (WAL) configuration
- Automated container orchestration
- Data persistence across container restarts
- Basic failover handling
- Docker Engine
- Docker Compose
- Git
├── docker-compose.yml
├── postgres-1/
│ └── config/
│ ├── postgresql.conf
│ └── pg_hba.conf
└── postgres-2/
└── config/
├── postgresql.conf
└── pg_hba.conf
- Clone the repository:
git clone https://github.com/pawarspeaks/postgresql-cluster.git
cd postgresql-cluster
- Launch the cluster:
docker-compose up -d
- Verify cluster status:
docker-compose ps
- Connect to primary node:
docker exec -it postgres-1 psql -U postgres
- Check replication status:
SELECT * FROM pg_stat_replication;
- Simulate primary node failure:
docker-compose stop postgres-1
- Verify secondary node status:
docker exec -it postgres-2 psql -U postgres -c "SELECT pg_is_in_recovery();"
Key configuration files:
postgresql.conf
: Contains replication settings like WAL configurationpg_hba.conf
: Manages host-based authentication for replicationdocker-compose.yml
: Orchestrates the PostgreSQL containers
@Pawarspeaks