Skip to content

PostgreSQL Slave Configuration

Ricardo Amendoeira edited this page Sep 8, 2015 · 5 revisions

Configuring a Streaming Replication Slave

Install PostgreSQL like you did for the Master server.

Don't worry if you already started this machine as a Master, you simply have to stop the server and delete the data folder so open up your trusty terminal and do:

  1. sudo service postgresql-9.4 stop
  2. sudo rm -rf /var/lib/pgsql/9.4/data

Now we need to replicate the database from the Master to our new slave:

  1. sudo su postgres

  2. pg_basebackup -D /var/lib/pgsql/9.4/data -h 192.168.1.1 -U replicador (change the IP address to your Master server's address)

As the postgres user open the folder /var/lib/pgsql/9.4/data and create inside it the file recovery.conf , with the following contents:

standby_mode=on

trigger_file='/tmp/promotedb'

primary_conninfo='host=192.168.1.1 port=5432 user=replicador application_name=postgresql1'

recovery_target_timeline='latest'

primary_conninfo is the Master server, so set the IP address and port accordingly, 5432 is the default port. application_name is the name you want this machine to identify itself as to the Master.

On a terminal run:

sudo service postgresql-9.4 start