0

I've built a Postgresql 12 HA system, one server is Master (s1) and the other is Slave (s2).

Assume the Master server (s1) failed due to power outage, and the Slave server (s2) got promoted to Master, what will happen when I turn on the Master server (s1) again? will it become Master and the Slave Server (s2) which currently Master be promoted again to Slave ? and will the Master Server (s1) resync what the Slave server (s2) handled while it was down ?

frisky5
  • 29
  • 10
  • It depends on the software you are using for HA. Usually no. Old slave becomes new master and old master needed to be restored from the new master and then becomes new slave. – Abelisto Feb 29 '20 at 10:42
  • @Abelisto should a a full restore be done, like take a base backup and then restore on new slave and then let it Stream replicate from the new Master ? – frisky5 Feb 29 '20 at 14:30
  • Generally if something went wrong with current Master what caused failover, the old master is corrupted by default. If base backup is a problem you can try just to change role of the old Master to Slave and look is it can to start and work. If not then, obviously the base backup is necessary. – Abelisto Feb 29 '20 at 16:36
  • In this circumstance I usually wipe the old corrupted master db, register it as slave and set up replication from the current master. Then I just promote it to master again. That way there is no outage. If the slave that was promoted to master is fine, then there is no need to restore from backup because it will have the most current state of data. (good to have backups though either way). – Julia Leder Mar 01 '20 at 01:27
  • What if the master went down due to power outage and no corruption happened, it'll just need to be promoted as slave and it will sync with the new Master automatically ? – frisky5 Mar 02 '20 at 06:53

1 Answers1

0

PostgreSQL doesn't do automated failover, you need to be using some other software to do that, and you haven't described what that is.

If you manually promote the replica to be the new master, then if you just turn on the old master it will still think it is the master. Unless the networking level prevents anyone from connecting to it, you will soon have corrupted data as some transactions are sent to one master and some to the other one.

jjanes
  • 37,812
  • 5
  • 27
  • 34