2

Is there a way where I can specify(include) both the master and slave server in nodejs db (postgresql) connecetion string in a replicated envirnment?

My aim is 'if master is down then the read/write should go to the slave'

3
  • So, you want automatic client side fail-over? Such a feature exists in PgJDBC, but I haven't heard of it in any other client PostgreSQL drivers. Commented Mar 31, 2014 at 7:38
  • I've seen jdbc driver for mysql to achieve this: "jdbc:mysql://master:3306,slave:3306/databasename" Looking for same in postgresql too Commented Apr 1, 2014 at 6:31
  • There's no failover in libpq, which most drivers over than pgJDBC use. So I doubt it, but a client driver could add it. You need to be very careful with this though: the replica write will fail if the replica is still a streaming replica, because it's read-only. Even if it didn't, you'd risk issues of divergence, where some writes go to one DB and some to another, creating a nasty data mess. Commented Apr 1, 2014 at 6:34

1 Answer 1

0

Even if nodejs does include this functionality(it shouldn't), you should really rely on something like pgpool to handle this. You can set it to favor the slave, for reads(or not), and configure it to push all writes to master.

This is really not something that should be handled by your framework.

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.