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'

Ajo Augustine
  • 1,252
  • 4
  • 16
  • 21
  • 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 07: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 01 '14 at 06: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 01 '14 at 06:34

1 Answers1

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.

Mike Shultz
  • 151
  • 1
  • 7