Postgresql Priamry-Replica Auto-Setup
Automate the configuration of a primary-replica
architecture for PostgreSQL
under Docker Compose
using a Makefile
and shell
script.
Demo
![demo](https://raw.githubusercontent.com/jason810496/Postgresql-Primary-Replica-Auto-Setup/main/docs/demo.png)
Click image to watch demo video on YouTube ☝️
Usage
make all
# wait input of `pg_basebackup` command with `REPLICA_PASSWORD` password authentication input
REPLICA_PASSWORD
is the password of theREPLICA_USER
user in theprimary
container.
REPLICA_PASSWORD
can be set in thedb.env
file.
Project Structure
.
├── 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_file
directive and the*.sh
scripts.pg_hba.conf
PostgreSQL host-based authentication configuration file.
We use this to allow thereplica
to connect to theprimary
.
Will be copied to theprimary
container.postgresql.conf
- PostgreSQL configuration file.
db.env
POSTGRES_PASSWORD=postgresql_password
POSTGRES_USER=postgresql_user
POSTGRES_DB=postgresql_db
REPLICA_USER=repluser
REPLICA_PASSWORD=replpass
db_volumes
primary
- PostgreSQL data directory for theprimary
container.replica
- PostgreSQL data directory for thereplica
container.primary_copy
- Volume for copying theprimary
data directory to thereplica
data directory.
Requirements
- Docker Compose
- Make
- Bash
References
- twtrubiks : postgresql master slave video tutorial
- twtrubiks : postgresql note - master slave
- editor.leonh.space : postgresql replication
Issues & PR
Feel free to open an issue !
Pull requests are welcome.
Any contributions you make are greatly appreciated.