Skip to content

Instantly share code, notes, and snippets.

@MbuguaCaleb
Last active August 14, 2019 07:52
Show Gist options
  • Save MbuguaCaleb/76e566a67b88471decfb71253ec38ab4 to your computer and use it in GitHub Desktop.
Save MbuguaCaleb/76e566a67b88471decfb71253ec38ab4 to your computer and use it in GitHub Desktop.
POSTGRES REPLICATION
# Viewing your Posgtres Clusters
sudo pg_lsclusters
# create a second postgres cluster
sudo pg_createcluster 10 replica1
#checking the status of the cluster
sudo pg_ctlcluster 10 replica1 status
sudo systemctl status postgresql@10-main
# create archive directories for both clusters
This is where the wal keep segments are stored
sudo -H -u postgres mkdir /var/lib/postgresql/pg_log_archive/main
sudo -H -u postgres mkdir /var/lib/postgresql/pg_log_archive/replica1
## Configure Main Cluster (Primary / Master) ###################################################
# edit configuration file
sudo nano /etc/postgresql/10/main/postgresql.conf
# edit host based access file
sudo nano /etc/postgresql/10/main/pg_hba.conf
This enables your server to accept connections with the replica
This should be set more securely in production
# create replication user
sudo -H -u postgres psql -c "CREATE USER rep_user WITH replication;"
# restart the main cluster
sudo systemctl restart postgresql@10-main
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment