node-postgres icon indicating copy to clipboard operation
node-postgres copied to clipboard

Replica/master/slave connect

Open 1999 opened this issue 9 years ago • 9 comments

Hey,

We have a simple replicaset/master-slave configuration of Postgresql: 1 master and 2 slaves. Right now I can't see any option to connect to only master and make insert ops there. Or am I missing smth?

1999 avatar Feb 04 '16 18:02 1999

This pg driver does not handle directly clusters as you described. You should create a little wrapper that will create a master pool and a pool for each of your slaves, and a functions to fetch a connections from master or slave.

akayami avatar Feb 18 '16 16:02 akayami

Is there any need of merging this functionality into pg?

1999 avatar Feb 18 '16 21:02 1999

cc @brianc

1999 avatar Mar 01 '16 11:03 1999

@1999 Most database libraries support this kind of a setup, so I think it makes sense for this to be added.

yocontra avatar Dec 08 '16 16:12 yocontra

:+1:

vsesh avatar May 28 '18 12:05 vsesh

I am running into a need to implement this as well.

I am going to write a higher level abstraction based on a principal that client.connect() and pool.connect() will be using writable master and queries made pool.query() will use read-only slave. I guess something along the lines of this + configuration could be added to node-postgress.

gajus avatar Jun 26 '18 22:06 gajus

Any updates on this, how to achieve master and slave using node pg, or anyone who has written wrapper as suggested.

This is very basic usecase and it should be in pg itself.

tarunsinghh avatar Apr 03 '22 19:04 tarunsinghh