How to do it...

For this scenario, the server at 192.168.56.10 is the primary PostgreSQL server, and 192.168.56.20 will be the asynchronous replica. Follow these steps to build a PostgreSQL asynchronous replica:

  1. Give the rep_user user a password with this SQL statement:
        ALTER USER rep_user WITH PASSWORD 'newpass';
  1. On the primary server, modify the pg_hba.conf line and remove any references to the rep_user user. Then, add this line:
        host   replication   rep_user   192.168.56.20/32   md5
  1. Reload the configuration files on the primary server with the following command as the postgres user:
        pg_ctl -D /db/pgdata reload
  1. On the replica server, create a file named .pgpass in the postgres user's home directory with the following contents:

Get PostgreSQL High Availability Cookbook - Second Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.