- Create user replication in the master
sudo -u postgres psql -c "CREATE USER rep REPLICATION \
LOGIN ENCRYPTED PASSWORD 'thepassword';"
- Modify
postgresql.conf
in the master
listen_address = # make sure we're listening as appropriate
wal_level = hot_standby
max_wal_senders = 3
checkpoint_segments = 8
wal_keep_segments = 8
- Add rule to
pg_hba.conf
in the master
hostssl replication rep 1.2.3.4 md5
- Ensure you have ssl activated in the
postgresql.conf
master
ssl = true
- Create
server.crt
andserver.key
files in the master if they don't exist.
Check
ls -l /var/lib/postgresql/$POSTGRES_VERSION/main/ | grep server
Create
sudo -u postgres ln -s /etc/ssl/certs/ssl-cert-snakeoil.pem /var/lib/postgresql/$POSTGRES_VERSION/main/server.crt
sudo -u postgres ln -s /etc/ssl/private/ssl-cert-snakeoil.key /var/lib/postgresql/$POSTGRES_VERSION/main/server.key
- Modify
postgresql.conf
in the slave
wal_level = hot_standby
max_wal_senders = 3
checkpoint_segments = 8
wal_keep_segments = 8
hot_standby = on
- As a
postgres
user clone this repo in the slave
cd /var/lib/postgresql
git clone https://gist.github.com/67da7f9aa3faf45ceb3d.git replication
- Run the
replication/replicate_postgres.sh
script in the slave
Add the following parameter:
If you need to backup a DB and the WAL_Segments may generate meanwhile.