We'll assume the following environment:
🐘 | 💾 |
---|---|
OS | CentOS 7 |
PostgreSQL version | 12 |
Master IP | 172.31.18.31 |
Slave IP | 34.243.240.207 |
$PGDATA | /var/lib/pgsql/12/data |
All steps should be performed as
postgres
user, unless otherwise stated.
-
Configure
postgresql.conf
andpg_hba.conf
(see sample configs) -
Create replication user
psql -c 'CREATE USER replica replication;'
sudo service postgresql-12 restart
-
Remove the contents of
$PGDATA
-
Perform backup
pg_basebackup -D "$PGDATA" -h 172.31.18.31 -U replica
-
Add
recovery.conf
to $PGDATA (see sample file) -
Set
hot_standby = on
inpostgresql.conf
-
Start postgres server
/usr/pgsql-12/bin/pg_ctl -D "$PGDATA" start
- (Probably unnecessary)
sudo service postgresql-12 restart