PostgreSQL 8.4 – Is Automatic Failback Possible via Log Shipping/PITR

log-shippingpostgresql-8.4replication

I have successfully setup continuous archiving and recovery of a master and slave node with PostgreSQL 8.4 via log shipping. I'm using keepalived to monitor both nodes and I can successfully trigger failover.

If I immediately bring the old master back online after the failover, such that log shipping immediately resumes, the master just sits there waiting for a WAL file that never arrives. It appears to be a timeline issue where the old master is looking for WAL files from what it knew the last timeline to be, but by design, the new master advanced the timeline.

I've seen some related discussions that seem to indicate that automatic failback isn't possible but they seem to involve later versions of postgres and streaming replication.

Is automatic failback possible, assuming the log shipping resumes as it should, or would one have to redo the process of making a base backup, copying it to the old master, then resuming log shipping?

EDIT: It occurred to me that I didn't mean automatic failback so much as I want the old master to rejoin the cluster as a standby.

Thanks

Best Answer

In general, no, not possible to turn the original master into a standby of the new master without making a copy of the new master, replacing all the data files of the old master with said copy, and resuming log shipping.

This is because, in general, there will be lost transactions on the old master that didn't make it to the standby.

You could use rsync to make the copy go faster -- as the contents of the two databases will likely be very similar. The tool pg_rewind was invented for this purpose: it will "rewind" the old master to the point at which the failover happened.

See Heikki Linnakangas' excellent presentation about the whole topic at http://hlinnaka.iki.fi/presentations/NordicPGDay2015-pg_rewind.pdf