-
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Querystring in connection string #1095
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
Comments
I know what you're talking about, and I agree it would be good to be able to pass more parameters to postgres during startup rather than hard-coding the few we're sending. One thing is I don't think connecting w/ a url is actually the best approach. Especially because Ideally there would be a separate npm module that would accept either a connection string and turn it into a config object with the connection string already parsed. Then if someone wants to use a connection string they could do so like:
That way it pulls the connection string parsing out of this library, where it can be better tested, cover more use cases, and evolve faster. To maintain backwards compatibility we could consume this module from node-postgres itself and do something like |
I'm pretty sure
|
yeah you're right I just checked on that - haha. Yeah, we need to make it easier to pass whatever options down to the client/pool/whatever and have them sent to the backend. Right now it's a "whitelist" kind of approach which is unfortunate. |
I'd like to look into this, PR for I'll try to dig into this on my own some time, but would be nice if you (or someone else) could maybe explain connection flow here, if that's not too much hassle.
That's the word I was looking for! :) |
Sure...so how connection works is pg authenticates with the database after authentication pg sends a bunch of settings to establish the session and configure the application name and other stuff... It does so by first getting the bundle of settings to send: So modifying the As for the native connection we take the config object and turn it into a "keyword/value connection string" here: https://github.com/brianc/node-postgres/blob/master/lib/connection-parameters.js#L74 That string is then passed unmodified to libpq where its converted into properties & sent to the postgres backend by libpq. The reason for doing a dns lookup in |
This is definitely the right thing to do, aligning connection parameters with what PostgreSQL supports. The driver is seriously lacking in that area at the moment. There are many parameters that PostgreSQL supports, and they all should be supported by |
Uh oh!
There was an error while loading. Please reload this page.
The problem
Postgres supports a bunch of stuff in connection strings:
https://www.postgresql.org/docs/9.5/static/libpq-connect.html#LIBPQ-CONNSTRING
However,
ConnectionParameters
,pg-connection-string
andpg.Pool
's config seem to only be aware about certain limited subset (likessl
,fallback_app_name
and others). Doesn't seem practical to validate those in node, since server will already reject invalid config (I think).Usecase
Instead of running a bunch of
set X to Y
after connecting to postgres on every client, I'd like to specify some session settings on connection string. In particular, I'd like to reproduce the followingpsql
invocation from the node:Solution
Probably parse the whole query string and pass everything we found in it to the server. Not sure how connection flow works, and how to use those parsed params.
Looks like there are a bunch of places need to be change in order to achieve this. Not sure if these are all of them:
pg-connection-string
'sparse
function;pg.Client
;pg.ConnectionParameters
;pg.Pool
's constructorI would be happy to PR this, but I'm not sure where to start. Any tips?
As a sidenote, would be neat to support this stuff:
psql options="-c\ timezone=Europe/Moscow"
.The text was updated successfully, but these errors were encountered: