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'

  • 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. – Craig Ringer Mar 31 '14 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 – Ajo Augustine Apr 1 '14 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. – Craig Ringer Apr 1 '14 at 6:34
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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.