Sync process is:
- make a base backup
- catch up with changes that happened during the base backup using master's WAL files
- stream
Make sure master's wal_keep_segments
is set to a high enough value to allow tracking all changes happening during the base backup. Restart needed when changing this.
On master, pg_hba.conf:
host replication all <slave ip>/24 trust
To reload pg_hba without restarting:
sudo pg_ctlcluster 9.3 main reload
On slave:
- set
hot_standby
to "on" - stop postgresql service
rm -rf
postgres'sdata_directory
(/home/postgres/data here).
Then as postgres user (command can hang for a while before showing some output but then displays progress information):
pg_basebackup -h <master ip> -D /home/postgres/main -U postgres -v -P
Create /home/postgres/main/recovery.conf:
standby_mode = 'on' primary_conninfo = 'host=<master ip> port=5432 user=postgres'
Start postgres.
To monitor state on master:
psql -x -c "select * from pg_stat_replication;" -U postgres