node-postgres
node-postgres copied to clipboard
Replica/master/slave connect
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?
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.
Is there any need of merging this functionality into pg?
cc @brianc
@1999 Most database libraries support this kind of a setup, so I think it makes sense for this to be added.
:+1:
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
.
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.