Standby Server Replication - PostgreSQL 9.1

Prepare STANDBY Server

Set up a standby server with postgresql (same version as in the master server) installed, as described in Deployment

Stop postgresql in the standby server

service postgresql stop

On MASTER Server

Edit pg_hba.conf, adding the following entry

host all all <IP_OF_STANDBY_SERVER> <NETMASK_OF_STANDBY_SERVER> trust

Edit postgresql.conf, changing the following parameters

listen_addresses = '*'
hot_standby = on
max_wal_senders = 1
wal_level = 'hot_standby'
archive_mode = on
archive_command = 'cd .'
wal_keep_segments = 1000

Restart server and generate,copy SSH key and back up to the standby server, using following commands:

service postgresql restart
ssh-keygen
ssh-copy-id <IP_OF_STANDBY_SERVER>
BACKUP_LABEL="base-backup"
PORT="5432"
PGDATA="/var/lib/pgsql/data"
psql -p $PORT -c "select pg_start_backup('$BACKUP_LABEL');"
rsync -cva --inplace --exclude=*pg_xlog* $PGDATA/ <IP_OF_STANDBY_SERVER>:$PGDATA/
psql -p $PORT -c "select pg_stop_backup();"

On STANDBY Server

Create file recovery.conf in folder /var/lib/pgsql/data containing

standby_mode = 'on'
primary_conninfo = 'host=<IP_OF_MASTER_SERVER> user=postgres'
trigger_file = '/tmp/postgresql.trigger.$PORT'

Start postgresql using

service postgresql start

Check for errors in the log files using

cat /var/lib/pgsql/data/pg_log/*