2

I am learning about PostgreSQL streaming replication and so far I have learned how to create a slave cluster using:

pg_basebackup -x -R -D main -h host -p port 

I also have learned that I can promote a slave to be a master like this:

pg_ctl -D main promote 

or

pg_ctlcluster 9.4 main promote

(if you are working on Ubuntu).

What I like to do now is to say that my previous master is now a slave of the new master. So far I have learned that I can do it by removing the data directory of server, and running pg_basebackup again. This means that I have to wait until all of my files are copied back from the new master the old one, which means a lot of data traffic.

Is there another way to do the same thing without copying all the data again?

4

This means that I have to wait until all of my files are copied back from the new master the old one, which means a lot of data traffic

When using pg_basebackup, yes.

But, if you're confident that the existing files at the destination are almost identical to the source, rsync may be used. The rsync remote-update protocol is able to identify what parts of files changed to minimize the amount of data to transfer.

See examples of uses on the postgres wiki: Binary Replication Tutorial / Starting Replication with only a Quick Master Restart

My personal experience with rsync versus pg_basebackup is that rsync is good if the "new master" has not drifted that much from the state when it became master, like a few minutes of transactions on a moderately busy system. Otherwise it still works but pg_basebackup appears to be faster.

  • Just to be sure by pg_backup you mean pg_basebackup or I can use pg_backup to resync master and slaves ? – Beatles1692 Jul 4 '15 at 7:04
  • @Beatles1692: pg_basebackup, edited to fix. – Daniel Vérité Jul 4 '15 at 10:28

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.