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:
- Change the docker-compose-multislave.yml to docker-compose.yml
- Rerun the docker compose
docker-compose build && docker-compose up --force-recreate
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;
- Login as postgres:
- Change roles user
- Alter for SUPERUSER:
ALTER ROLE user SUPERUSER;
- Alter for REPLICATION:
ALTER ROLE user REPLICATION;
- Alter for SUPERUSER:
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)