Skip to content

guedim/postgres-streaming-replication

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

36 Commits
 
 
 
 
 
 

Repository files navigation

postgres-streaming-replication

This is a sample for master/slave Postgres database replication using Streaming replication

This is a simple project using docker swarm mode.

Table of contents

  1. Configuration
    1. Play With Docker
    2. Create swarm cluster
    3. Get the docker compose file
    4. Create the services
    5. Connect to master database
    6. Run scripts in master database
    7. Connect to slave database
    8. Verify scripts in slave database
  2. Todos
  3. License

Configuration

  1. Open a web browser and go to Play With Docker tool:
https://play-with-docker.com

  1. 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).

  1. 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
  1. Start the services in a Swarm Mode:
docker stack deploy --compose-file docker-compose.yml postgres-streaming-replication

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

  1. Create a table and insert some data in the master database.
-- 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');

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

  1. Finally, verify the data in the slave database:
-- Verify the data in the slave database
select * from replica_test;

Todos

  • How to use a cluster using streaming and logical replication

License


MIT

Releases

No releases published

Packages

No packages published