A replication architecture database is a valuable approach for separating read and write responsibilities into different database servers. This allows for efficient scaling of the database based on the type of operations or transactions that occur. In this guide, we will set up a replication architecture database in a Docker environment using Docker Compose, specifically for our development environment.
Technologies Used
- PostgreSQL
- Docker Compose
Getting Started
- Install Docker Desktop
Docker Compose Setup
Begin by creating a docker-compose.yaml file to define the services, configurations, and dependencies for the PostgreSQL replication setup.
version: "3"
services:
postgresql-master:
image: bitnami/postgresql
restart: always
ports:
- '5432:5432'
volumes:
- postgresql_master_data:/bitnami/postgresql
- ./db.sql:/docker-entrypoint-initdb.d/db.sql
environment:
- POSTGRESQL_PGAUDIT_LOG=READ,WRITE
- POSTGRESQL_LOG_HOSTNAME=true
- POSTGRESQL_REPLICATION_MODE=master
- POSTGRESQL_REPLICATION_USER=repl_user
- POSTGRESQL_REPLICATION_PASSWORD=repl_user
- POSTGRESQL_USERNAME=postgres
- POSTGRESQL_PASSWORD=postgres
- POSTGRESQL_DATABASE=development_database
- ALLOW_EMPTY_PASSWORD=yes
postgresql-slave:
image: bitnami/postgresql
restart: always
ports:
- '5432'
depends_on:
- postgresql-master
environment:
- POSTGRESQL_PASSWORD=postgres
- POSTGRESQL_MASTER_HOST=postgresql-master
- POSTGRESQL_PGAUDIT_LOG=READ
- POSTGRESQL_LOG_HOSTNAME=true
- POSTGRESQL_REPLICATION_MODE=slave
- POSTGRESQL_REPLICATION_USER=repl_user
- POSTGRESQL_REPLICATION_PASSWORD=repl_user
- POSTGRESQL_MASTER_PORT_NUMBER=5432
- ALLOW_EMPTY_PASSWORD=yes
volumes:
postgresql_master_data:
driver: local
This docker-compose.yaml file defines two services: postgresql-master and postgresql-slave. The postgresql-master service acts as the master node, while the postgresql-slave service acts as the slave node.
Explanation of Key Configurations
- PostgreSQL Master Service:
POSTGRESQL_REPLICATION_MODE=master: Specifies that this PostgreSQL instance is the master.POSTGRESQL_REPLICATION_USERandPOSTGRESQL_REPLICATION_PASSWORD: Credentials for replication.POSTGRESQL_DATABASE: Name of the development database.POSTGRESQL_PGAUDIT_LOG=READ,WRITE: Enables audit logging for read and write operations.
- PostgreSQL Slave Service:
POSTGRESQL_REPLICATION_MODE=slave: Specifies that this PostgreSQL instance is the slave.POSTGRESQL_MASTER_HOST: Points to the host of the master node.POSTGRESQL_MASTER_PORT_NUMBER: Port number on which the master node is running.POSTGRESQL_PGAUDIT_LOG=READ: Enables audit logging for read operations.
Running the Setup
To start the PostgreSQL replication setup, navigate to the directory containing the docker-compose.yaml file and run:
docker-compose up -d
This will launch the services in detached mode. You can then access the master and slave databases separately, and any changes made in the master will be replicated to the slave.

This Docker-Compose setup provides a convenient way to implement PostgreSQL database replication for your development environment. Adjust the configurations based on your specific requirements and scaling needs.

Keep Reading
-
AI Tools for Kubernetes Operations: Your Complete Guide to Smarter Clusters
The era of intelligent Kubernetes management has arrived. Gone are the days of manually sifting through logs, guessing at resource allocations, or scrambling during incidents. Today’s AI-powered tools are transforming how we troubleshoot, optimize costs, and build self-healing infrastructure. This deep dive explores five game-changing tools that every Kubernetes practitioner should know: K8sGPT, CAST AI,…
-
How DevOps Teams Can Reduce Cloud Spend Using Modern FinOps Tools
If you work in DevOps, you’ll already know that cloud spending can creep up month after month. Teams move fast, new environments get spun up, and workloads scale long after traffic goes back down. Before long, the bill surprises everyone. Cloud waste is a real problem, and most teams underestimate how much of their spend…
-
Kubernetes CI/CD Pipelines – 8 Best Practices and Tools
Learn how to build robust, scalable, and secure CI/CD pipelines for Kubernetes. This comprehensive guide covers 8 essential best practices along with the top tools that DevOps teams use to streamline container deployments, implement GitOps workflows, and achieve continuous delivery at scale.

