/docker-postgresql-replication

Replication Master-Slave PostgreSQL with Docker

MIT LicenseMIT

Docker PostgreSQL Replication

Docker PostgreSQL Master-Slave Replication, run:

docker-compose build && docker-compose up

Requirements:

Configuration:

  • Environment
    • DB_USER=user
    • DB_PASS=_password
    • DB_NAME=_dbname
    • Create server (Master/Slave)
    • Connection
      • Hostname: 172.21.0.x
      • Port: 5432
      • Username: user
      • Password: password

Multi Slave Replication:

Optional:

  • Run kitematic & select the docker master/slave container, click on "EXEC" button, or using: docker exec -it [container_id] bash
  • Change owner database
    • Login as postgres:
      sudo -i -u postgres
      
    • Enter psql:
      psql
      
    • Alter database owner:
    ALTER DATABASE dbname OWNER TO user;
    
  • Change roles user
    • Alter for SUPERUSER:
      ALTER ROLE user SUPERUSER;
      
    • Alter for REPLICATION:
      ALTER ROLE user REPLICATION;
      

Check Replication Status:

  • After entering psql (master container):
    SELECT * FROM pg_stat_replication;
    
    • You can read all here

Common PostgreSQL Command:

  • List of database: \l
  • Connect to database (use database): \c [database_name]
  • View table database (after use): \dt
  • List of user roles: \du
  • Expand display: \x
  • Quit: \q

License

MIT License (MIT)