Automate the configuration of a primary-replica architecture for PostgreSQL under Docker Compose using a Makefile and shell script.
Click image to watch demo video on YouTube ☝️
make all
# wait input of `pg_basebackup` command with `REPLICA_PASSWORD` password authentication input
REPLICA_PASSWORDis the password of theREPLICA_USERuser in theprimarycontainer.
REPLICA_PASSWORDcan be set in thedb.envfile.
.
├── Makefile
├── README.md
├── db_volumes
│ ├── primary
│ ├── primary_copy
│ └── replica
├── docker-compose.yml
└── primary-replica
├── db.env
├── pg_hba.conf
├── postgresql.conf
├── reset.sh
├── setup.sh
└── test.sh
5 directories, 9 files
db.env- Environment variables for the Docker Composeenv_filedirective and the*.shscripts.pg_hba.confPostgreSQL host-based authentication configuration file.
We use this to allow thereplicato connect to theprimary.
Will be copied to theprimarycontainer.postgresql.conf- PostgreSQL configuration file.
POSTGRES_PASSWORD=postgresql_password
POSTGRES_USER=postgresql_user
POSTGRES_DB=postgresql_db
REPLICA_USER=repluser
REPLICA_PASSWORD=replpassprimary- PostgreSQL data directory for theprimarycontainer.replica- PostgreSQL data directory for thereplicacontainer.primary_copy- Volume for copying theprimarydata directory to thereplicadata directory.
- Docker Compose
- Make
- Bash
- twtrubiks : postgresql master slave video tutorial
- twtrubiks : postgresql note - master slave
- editor.leonh.space : postgresql replication
Feel free to open an issue !
Pull requests are welcome.
Any contributions you make are greatly appreciated.
