PostgreSQL Failover – How to Automate Failover with Trigger File Creation

failoverpostgresqlreplication

Is there a way to detect if the master PostgreSQL (9.3) server becomes unresponsive, and if so, create the trigger file (that is specified in recovery.conf) that initiates the failover process?

Or more specifically, is there some kind of ping or keepalive command that you can use from the slave to see if the master is responding? If so, this can probably be implemented with a shell script rather easily. I have not yet found a command that does something similar to this. Any help is appreciated, thank you.

Best Answer

repmgr 2.0 supports automatic failover.

However, I strongly advise you not to use automatic failover. It's generally a much better idea to use manually triggered automated failover, where the failover process is scripted/automated, but a human has to say "Yup, master's dead, do it".

If you do use automatic failover you need to make it a routine part of your operations, where you test it regularly. Otherwise it will bite you when you least expect it and can least afford it.

It is also vital that you consider fencing/STONITH as part of your failover solution, to prevent two diverging masters.