This is a sample for master/slave Postgres database replication using Streaming replication
This is a simple project using docker swarm mode.
- Open a web browser and go to Play With Docker tool:
https://play-with-docker.com
- Create one instache, however to avoid performance issues we recommend you to create a swarm cluster using the PWD templates (3 Managers and 2 Workers or 5 Managers and no workers).
- Download the docker-compose file in the new instance created in the above step:
wget https://raw.githubusercontent.com/guedim/postgres-streaming-replication/master/docker-compose.yml
- Start the services in a Swarm Mode:
docker stack deploy --compose-file docker-compose.yml postgres-streaming-replication
- Go to PgAdmin portal (clic in 5050 port) and register the master database.
Open the PgAdmin for master database with the next credentials:
- user: masterdatabase
- password: 12345678
Register the master database with:
- user: postgres
- password: postgres
- password: 5432
-- Create a sample table
CREATE TABLE replica_test (hakase varchar(100));
-- Insert sample data
INSERT INTO replica_test VALUES ('First data in master');
INSERT INTO replica_test VALUES ('Second data from master database');
INSERT INTO replica_test VALUES ('3rd and final data from master database');
- Go to PgAdmin portal (clic in 5060 port) and register the slave database.
Open the PgAdmin for slave database with the next credentials:
- user: slavedatabase
- password: 12345678
Register the slave database with:
- user: postgres
- password: postgres
- password: 5433
-- Verify the data in the slave database
select * from replica_test;
- How to use a cluster using streaming and logical replication
MIT