I have a streaming replication setup using postgresql 9.3. I have two servers, the master (server_1) and the slave (server_2).

The other day I did a failover to my slave (server_2). Now server_2 has been running as master for a couple of days, and I have now setup my primary master (server_1) again, and it now runs as master. I would like to avoid reinstalling server_2 before turning it into a slave of server_1 again. How can I do that? What dir's should I delete etc, in order to have a "clean" server that I can use as slave again?

1 Answer 1


The only officially supported method is to make a new base backup, or:

  • pg_start_backup() on the new master
  • rsync from new master to old master
  • pg_stop_backup()
  • ensure WAL got copied over and applied
  • create recovery.conf
  • start resynced server

The 3rd party tool pg_rewind is intended for that purpose. I haven't worked with it as yet and can't vouch for it in production.

  • Sure, but don't I have to "delete" the old cluster from the to-be-slave, before I start doing the above? Commented Apr 2, 2014 at 10:31
  • @NielsKristian If you use pg_basebackup, yes. If you use rsync, no, because rsync can incrementally update it. Commented Apr 3, 2014 at 1:14
  • I see, that was actually the answer I was looking for! Thank you Craig, you are one of the most helpful persons I can think of :-) Commented Apr 3, 2014 at 8:18

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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