Report this

What is the reason for this report?

Postgresql replication: How to convert the old master to the new slave

Posted on February 19, 2017

Hi, I followed this tutorial (https://www.digitalocean.com/community/tutorials/how-to-set-up-master-slave-replication-on-postgresql-on-an-ubuntu-12-04-vps#configure-the-slave-server) to create a replication scheme between to postgresql servers (v9.5 on Ubuntu 16.04).

The only difference is that for the initial database replication I used this:

sudo -u postgres pg_basebackup -h 1.2.3.4 -D /var/lib/postgresql/9.5/main -U [username] -v -P -x

Then I tried to test the failover process.

  1. I stopped the master server
  2. I ‘touched’ the trigger file on the Server to make it read-write (it worked)
  3. Added some test data on the Slave’s (now Master) database (it worked)
  4. I switched to the old master server and (a) did a pg_basebackup from the new master and (b) created a recovery.conf file (ir worked)
  5. restarted the new slave (no problems)

However whatever change I make on the new Master, it won’t be coped to the new slave. Also the new slave is not read-only.

Can someone explain to me what did I do wrong?



This textbox defaults to using Markdown to format your answer.

You can type !ref in this text area to quickly search our full set of tutorials, documentation & marketplace offerings and insert the link!

These answers are provided by our Community. If you find them useful, show some love by clicking the heart. If you run into issues leave a comment, or add your own answer to help others.

Hello,

It’s possible that there may be an issue with your replication configuration. Here are some things you can check:

Check the postgresql.conf and pg_hba.conf files on both the master and slave servers to ensure that they are properly configured for replication.

Check the log files on both servers to see if there are any error messages related to replication.

Check the replication status by running the following command on the master server:

    SELECT * FROM pg_stat_replication;

This will show you if the slave server is connected and if replication is currently running.

Check that the replication slot is still active by running the following command on the master server:

SELECT * FROM pg_replication_slots;

If the slot is not active, you may need to recreate it on the new master.

Make sure that the WAL files are being properly archived and streamed to the slave server. You can check the pg_xlog directory on the master to see if new WAL files are being generated, and the pg_wal directory on the slave to see if they are being properly received.

The developer cloud

Scale up as you grow — whether you're running one virtual machine or ten thousand.

Get started for free

Sign up and get $200 in credit for your first 60 days with DigitalOcean.*

*This promotional offer applies to new accounts only.