Replication Master-Slave with PostgreSQL 9.4 in Ubuntu 14.04

My scenario is I have two servers at addresses 192.168.1.191 and 192.168.1.171, and installed Ubuntu 14.04 and PostgreSQL 9.4.

To know how to install PostgreSQL, please read Install PostgreSQL 9.4 in Ubuntu 14.04

Step 1: Make sure that the two servers are able to SSH freely between them

Switch to Postgres account:

Generate ssh key:

Copy SSH key to opposite server:

Note: you have to do this step for the both servers 

Step 2: Setup Master Node

Create an account for replication

Modify postgres access config file:

Add content below:

And modify postgres config file:

The config value should be:

And now, restart Master server:

Step 3: Setup Slave Node

Stop PostgreSQL:

Modify postgres access config file:

Add content below:

And modify postgres config file:

The config value should be:

Step 4: Start the replication

In Master Server, run command below to start the replication

In Slave Server, create recovery.conf file:

And add the content below to that file:

And restart Slave Server to complete the setup:

It is time for testing, you can try to create and insert data to Master Server. It will be synchronized to Slave Server