Skip to content

jason810496/Postgresql-Primary-Replica-Auto-Setup

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

7 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Postgresql Priamry-Replica Auto-Setup

License: MIT DB : postgresql


architecture


Automate the configuration of a primary-replica architecture for PostgreSQL under Docker Compose using a Makefile and shell script.

Demo

demo

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 the REPLICA_USER user in the primary container.
REPLICA_PASSWORD can be set in the db.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 Compose env_file directive and the *.sh scripts.
  • pg_hba.conf

    PostgreSQL host-based authentication configuration file.
    We use this to allow the replica to connect to the primary.
    Will be copied to the primary 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 the primary container.
  • replica - PostgreSQL data directory for the replica container.
  • primary_copy - Volume for copying the primary data directory to the replica data directory.

Requirements

  • Docker Compose
  • Make
  • Bash

References

Issues & PR

Feel free to open an issue !

Pull requests are welcome.
Any contributions you make are greatly appreciated.

About

Automate the configuration of a primary-replica architecture for PostgreSQL under Docker Compose using a Makefile and shell script.

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors