Reputation: 95
I have set up streaming replication from a master DB to a slave DB. If the master is shut down, the slave will take over. The replication and failover works fine.
I have a web app using the master database for storing data.
Some details:
I want to continue using this method of doing replication.
The questions:
Upvotes: 4
Views: 2304
Reputation: 30079
Give PostDock a try if you would consider a Docker based solution.
Currently I have tried it in our project with docker-compose, with the schema as shown below:
pgmaster (primary node1) --|
|- pgslave1 (node2) --|
| |- pgslave2 (node3) --|----pgpool (master_slave_mode stream)----client
|- pgslave3 (node4) --|
|- pgslave4 (node5) --|
I have tested the following scenarios, and they all work very well:
As for the client application, these changes are all transparent. The client just points to the pgpool node, and keeps working fine in all the aforementioned scenarios.
Note: In case you have problems to get PostDock up running, you could try my forked version of PostDock.
A problem with the aforementioned architecture is that pgpool is the single point of failure. So I have also tried enabling Watchdog for pgpool-II with a delegated virtual IP, so as to avoid the single point of failure.
master (primary node1) --\
|- slave1 (node2) ---\ / pgpool1 (active) \
| |- slave2 (node3) ----|---| |----client
|- slave3 (node4) ---/ \ pgpool2 (standby) /
|- slave4 (node5) --/
I have tested the following scenarios, and they all work very well:
As for the client application, these changes are all transparent. The client just points to the virtual IP, and keeps working fine in all the aforementioned scenarios.
You can find this project at my GitHub repository on the watchdog branch.
Upvotes: 0
Reputation: 1332
I suggest having a look at pgpool with the failover_command option. There you can have a small shell script to restart the slave in read/write mode. pgpool
In case you run into some issues with pgpool, this process which I followed to troubleshoot might help - pgpool - stracing
Upvotes: 3
Reputation: 95
PGPool-II did the trick.
I installed PGPool on a third server; a monitoring server also running CentOS. I configured a health check to run every 10 seconds. The failover_command was set to run a small shell script that generates a trigger file on the slave server if the master server fails. And it worked perfectly.
To prevent the master from suddenly starting again, I´ll use two config files (one for master and one for slave) for the app server and extend the shell script to restart the app server using the slave config.
Thanks for the tip!
Upvotes: 1