Skip to content

Connection String with multiple hosts is not being parsed as expected #2308

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

Open
chandelabhishek opened this issue Aug 12, 2020 · 5 comments

Comments

@chandelabhishek
Copy link

chandelabhishek commented Aug 12, 2020

Hi There,

According to PG docs multiple hosts can be supplied in connection string.

for example:
If I supply connectionString as postgres://user:@localhost:6432,localhost:5432/db_name
it is being parsed as this:

{
    driver: 'postgres',
    user: 'user',
    password: '',
    database: ':6432,localhost/db_name',
    host: 'localhost',
    port: '5432'
}

above is throwing error. as the connection which gets constructed from this is wrong. This is the issue with pg-connection-string.

Also, I am curious, why do we need to parse a connection-string, why can't we directly pass it to libpq?

Will you accept a PR for this?

@wpatrik14
Copy link

I have just raised a similar issue to pg-native library: #
Duplicate of #brianc/node-pg-native#96

@beeing
Copy link

beeing commented Aug 22, 2021

Probably will be easier to use a middleware like pgpool or pgbouncer for this.

@lukos
Copy link

lukos commented Mar 6, 2023

The functionality that is important is that if I need to failover a database, I can do so without updating connection strings because the library will automatically choose a server that is the primary. I can't see that pgbouncer or pgpool have this functionality.

@boromisp
Copy link
Contributor

boromisp commented Mar 6, 2023

You can achieve that with a generic TCP reverse proxy, like HAProxy. First result in ddg for dynamically changing servers in haproxy: https://stackoverflow.com/a/53294153

But you get more features from postgres-aware programs, like pgpool:
https://www.pgpool.net/docs/latest/en/html/runtime-config-failover.html

I've never set something like this up before, the last time I've done postgres HA, it was with virtual IPs, but that usually isn't a good option in cloud environments.

@chandelabhishek
Copy link
Author

If this option is available, then it can do switchover by itself, as libpq has that capability. Then we don't need to maintain an extra moving part like ha-proxy or pg-pool.

thomasheartman added a commit to Unleash/unleash that referenced this issue Mar 17, 2023
This PR updates the docs to clarify that we don't support multi-host
strings in the databaseUrl configuration variable.

The docs used to just mention that we accept libpq strings, but as
reported in #3221, we **don't** support multi-host strings.

I did some digging and found that this is because [node-postgres -- the
library we use to connect to postgres -- itself does not support
multi-host
strings](brianc/node-postgres#2308).

To fix this, we would need to replace the library we use or otherwise
wrap it. While this would be a better long-term solution, we don't have
the capacity to it right now. But we can update the docs to better
reflect reality.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants