How to Set Up PostgreSQL Replication on CentOS 7

centos-7postgresqlreplication

Followed this guide to do the PostgreSQL replication:

https://www.digitalocean.com/community/tutorials/how-to-set-up-master-slave-replication-on-postgresql-on-an-ubuntu-12-04-vps

I didn't do this:

psql -c "select pg_start_backup('initial_backup');"
rsync -cva --inplace --exclude=*pg_xlog* /var/lib/postgresql/9.1/main/ slave_IP_address:/var/lib/postgresql/9.1/main/
psql -c "select pg_stop_backup();"

After I configed both master and slave nodes, test to create a table on master, didn't find new data been synced to slave.

From this guide I saw need to add a archive_command config in the recovery.conf file:

https://www.server-world.info/en/note?os=CentOS_7&p=postgresql&f=3

archive_command = 'cp %p /var/lib/pgsql/archive/%f'

But PostgreSQL 9.6 maybe not support that feature. So how can it been synced automatically?


Addition

It's helpful:

https://dalibo.github.io/PAF/Quick_Start-CentOS-7.html

Best Answer

The archive_command setting doesn't fit the recovery.conf but the postgresql.conf file.

The documentation you're following is deprecated.

Please switch to the official documentation.

Here are the steps you need to perform:

  • Primary node settings (postgresql.conf, pg_hba.conf)
  • Primary node backup (pg_basebackup, pgbarman, pgbackrest... Whatever)
  • Restoring on secondary node (manually, pgbarman, pgbackrest... Whatever)
  • Secondary node settings (recovery.conf, postgresql.conf, eventually pg_hba.conf)

The part you didn't do is simply the initial backup/restore. You can't do replication without it.