-
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Support for multiple hosts #1470
Comments
Renamed the title again, because the connection attempts as such are out of the scope, |
@vitaly-t Isn’t this something the pure-JS library should have feature parity with? |
I believe it should, yes. |
Notation that the connection string should support: https://github.com/mongodb/specifications/blob/master/source/connection-string/connection-string-spec.rst And then the driver needs to be extended accordingly. |
This would be super useful, the connection string is also described here http://paquier.xyz/postgresql-2/postgres-10-libpq-read-write/ and here https://www.postgresql.org/docs/10/static/libpq-connect.html A typical use case would be where repmgrd would take care of the automatic failover and the client would automatically reconnect to the new primary when a failover did occur I tried this but it is not working (primary and standby are running in docker containers on local host)
|
Just a health check, since this was open 6 month ago... Any attempt at implementing this yet? |
Generic connection-string is now available, which supports the full multi-host notation. This library should be used in place of the current connection string parser. |
Good day, have you plans to fix this issue and move to |
I make PR to connection-string lib for compatible with node-postgres. |
Any news? I see a bunch of PR open, but can't get what blocks it currently. |
@PavelPolyakov There’s a single PR that doesn’t contain the implementation of the feature. |
@charmander Thanks, that was confusing. @vitaly-t , can you, please, describe the current state of your endeavour? I mean If things are clearer it would be easier to help. |
@PavelPolyakov Nothing changed about connection-string, and not going to. It was and remains the correct URL parser for connection strings. And I rejected PR from @denchistyakov because it contradicts the URL specification, and the hack for spaces that's used in See also the useful Adapters. |
@vitaly-t Thanks for the answer, but current state is still not clear to me. I have two questions:
I also see that there is this MR open: #1711. However it is said, that it lacks implementation :) Thank you |
I can integrate |
Cool, that makes it more clear. So, basically, the real blocker is that multiple hosts support is not yet available here: https://www.npmjs.com/package/pg-native and here https://github.com/brianc/node-postgres/blob/master/lib/client.js . Is that right? |
Seems that way 😄 |
@vitaly-t are you sure? I've just tested if It is able to connect to the |
@nyurik |
Thanks @PavelPolyakov , I was hoping to avoid the extra complexity (e.g. still not sure which I shuold use - HAProxy vs PgPool-II vs Pgbouncer), and also possibly solve the dynamic nature of the pool - e.g. as replicas are added and removed, I was hoping my node-js code could transparently scale the number of requests to the servers, or at least assume that the client-side pg pool or the proxy would throttle the execution based on how many replicas are available. Thanks for the quick reply! |
Any update on this? Or if there is another npm library? |
I ended up writing multi-pool logic as part of my lib, load-balancing between multiple pools, and taking per-serve weight into account. I'm still hoping for a more generic solution. https://github.com/nyurik/tilelive-pgquery/blob/master/lib/PgQuery.js#L106 |
@nyurik Does the lib you mentioned handles detection of primary and secondary nodes basically write and read query redirection to primary and secondary respectively? |
@shreeramk my lib implements just one specific use case - load balancing reads from identical replicas or the master. It simply runs the SELECT query without considering if it is a primary or secondary, but it could be configured to send fewer queries to the primary (based on the server's hostname, not on its present status) |
@nyurik ok. Have you implemented automatic failover in postgres? Also, in case of failover, do you modify manually the connections in your nodejs code? |
@shreeramk no, that's also a todo. In theory all this functionality could be refactored out into the node-postgres lib, or a standalone lib. |
Hi, all, I want to ask a question, |
@PavelPolyakov, @vitaly-t is there any fix done for JS driver supporting multi-host, and we can use it? |
@kalemayur8 I believe there is none so far |
Still nada, as of this day 😞 We need JS version of the library to start supporting multiple hosts. I have provided the solid implementation of connection-string that follows the standard, but that's as far as I could contribute. |
the whole point is to switch between hosts when getting
|
@RazgrizHsu Doing what All you need to do is loop over the different hosts, finding the first one that is available and indicating it is not in recovery. To check if a host is in recovery (if it is, it is the secondary), you can use a special query such as Note that there is a slight difference if you want to :
|
Hi, I've run across this because I'd like to connect to CockroachDb (which is wire-compatible with PostgreSQL) from my app using either TypeORM or MikroORM, both of which use Is there anything I can do to help add support for this feature? I'm happy to try writing a PR implementing the logic described by @K3UL, would that be acceptable? |
Guys any news with multi host support?) |
Hello More info on this is very appreciated. Thanks |
hi all, Any news about the multi-hosts? |
we had to switch to this lib https://github.com/porsager/postgres?tab=readme-ov-file#multi-host-connections---high-availability-ha, and can confirm it works and also support pretty much all functionalities. The ability to support multiple hosts is a must to have for a enterprise level system |
Does it work with any ORMs? I saw that driver a few years ago and really liked it but I was not sure it was production ready. |
Hey, also looking into this, we recently started using |
+1 for this feature. This feature is supported in rust-postgres, psycopg, asyncpg, sqlalchemy, even ODBC postgres. I see no reason why there should not be some form of support for this functionality, extremely useful in enterprise environments to implement high availability and load balancing without any middleware or DNS to configure. |
PostgreSQL v10 was released on Oct 05, 2017, see the Release Notes.
One of the most interesting features that affects
node-postgres
is multiple host names or addresses in libpq connection strings and URIs.This feature allows automatic support for replicas through the connection string, i.e. the first connection is tried, and if fails - the next one, and so on.
From documentation:
It may require some work within the driver to support it, but it will be very much worthwhile 😉
The text was updated successfully, but these errors were encountered: