subhojit_paul
subhojit_paul

Reputation: 31

POSTGRES REPLICATION for new master

We are putting together an architecture to support High Availability for our Postgres 9.5 Database. We have 1 master and 3 slaves Replicating the data of the master. When The master goes down Slave 1 is promoted to new master but Slave 2 and Slave 3 are still pointing to the previous master and not the updated master node. Is there a way to make the slaves to read from the new master dynamically . Or does it require changing the configurations manually and restarting the slaves?

Upvotes: 1

Views: 1893

Answers (2)

Aleksandar Pesic
Aleksandar Pesic

Reputation: 678

There's no short answer, but I'll try:

  • When primary server fails you'll promote one slave, and reconfigure all other slaves to target the new master. However there's one scenario in which reconfiguring other slaves might not be needed: if you are using "WAL archiving", and your archive is stored on a shared drive which survived the failure of the old primary. If the new primary continues to use the same shared store you might not need to reconfigure other slaves. Again, I've never tried this - you can try.
  • If your replication mechanism is based on "replication slots" (introduced in PostgreSQL 9.4) - then you have to reconfigure all the slaves. In this case actually you'll have to rebuild replication on all other slaves from scratch (as if they've never been slaves at all). Nevertheless, in my opinion "replication slots" are better choice.

Regarding automation: You've asked if it is possible to automatically reconfigure other slaves, but thing you've missed to mention is if you have any failover automation implemented. What I'm trying to say is that PostgreSQL itself will not automatically perform failover (promote one of slaves when the master fails). At least you have to create "trigger file" on the slave to be promoted, and you have to do this manually or by using another product (for example pgpool2).

If you use pgpool2 - you can setup automatic slave reconfiguration by setting follow_master_command pgpool.conf value.

Finally I'll strongly recommend reading this tutorial - it'll make your life easier.

Edit: I've forgot to say two things:

  • Automatically reconfiguring all other slaves as soon as the new master is promoted might not be a good idea, especially if you have many slaves. It'll put additional pressure on your new primary, and on your network, so in some cases it is better to postpone this for night hours for example. More on this in the mentioned tutorial.
  • I've wrote the tutorial.

Upvotes: 1

Md.Alauddin Hossain
Md.Alauddin Hossain

Reputation: 186

As e4c5 commented, you can use repmgr for managing this type of tasks. I have tried repmgr and I was done without a problem.

I have followed a tutorial for doing that and here is the link:

http://jensd.be/591/linux/setup-a-redundant-postgresql-database-with-repmgr-and-pgpool

I hope following this tutorial you can do what you want without any problem.

Upvotes: 0

Related Questions