-
Notifications
You must be signed in to change notification settings - Fork 894
Use query to find the current catalog instead of relying on the database in the connection URL or connection properties as this could be different if connected through a pooler or proxy #3565
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
Conversation
@vlsi I'd like to merge this. Any issues ? |
@@ -218,6 +218,8 @@ private enum ReadOnlyBehavior { | |||
private final @Nullable String xmlFactoryFactoryClass; | |||
private @Nullable PGXmlFactoryFactory xmlFactoryFactory; | |||
private final LazyCleaner.Cleanable<IOException> cleanable; | |||
/* this is actually the database we are connected to */ | |||
private String catalog; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
private String catalog; | |
private @Nullable String catalog; |
I guess we have @SuppressWarning
for PgConnection
constructor, so it results in silencing warning for the newly added field.
However, the field is nullable, so let's specify nullable type.
…ase in the connection URL or connection properties as this could be different if connected through a pooler or proxy Update pgjdbc/src/main/java/org/postgresql/jdbc/PgConnection.java Co-authored-by: Vladimir Sitnikov <sitnikov.vladimir@gmail.com> fix checkstyle fix checkstyle
30e1fec
to
8b722e9
Compare
Let me preface this by saying I'm not opposed to this PR ... though thinking about this a couple questions came to mind. What happens if the DB changes? The whole point of this PR is to skip the fixed value in connection properties and pass through to the actual database, potentially bypassing any intermediate connection pool(s). If the pooler reroutes the connection somewhere else then it'd be wrong as we would have cached the previous value. I suppose that type of pooling is less common, but it does come up for things like live migrations and upgrades. There's also a slight change in behavior here. Previously the method was a pass through to We could resolve this by caching the value at connection startup. But I don't think we want to add more mandatory startup round trips. |
Actually one point of the PR is to make sure we get the right database. If you use pg_bouncer then you connect to some database in pg_bouncer which redirects you to the actual database. Q: How can the database change ? |
The situation I'm describing is where the pooler swaps out the physical connection. There's no guarantee I get the same catalog when it opens a new connection. Interestingly I found this pgbouncer fork (replacement?) which seems to do exactly what I'm describing: https://github.com/awslabs/pgbouncer-fast-switchover Imagine configuring that with multiple targets that have different database names. Could be the same actual database, just the return value of |
Well our options are to query the database every time or cache it. |
Or return the original value and have people who are doing that pooling stuff explicitly query for the live one themselves. |
It would be great if |
That is really a pg_bouncer problem. In reality the server will never change the catalog once the connection is established. I think we could get pg_bouncer to emit |
My feeling exactly. However, if we expect |
thanks for this PR, 42.7.6 fixes a regression that was introduced with #3390. Using 42.7.3 against a database cnx handled by pgbouncer having a different name/alias than the real database, geotools was able to list attributes/fields in a layer/table without issues, while it started failing after an update to 42.7.5. turning replacing 42.7.5 jar by 42.7.6 jar, everything works as before, so thanks @davecramer ! |
fixes access to a database behind a pgbouncer alias which doesn't match the real database name, cf pgjdbc/pgjdbc#3565 more analysis in GEOS-11849
fixes access to a database behind a pgbouncer alias which doesn't match the real database name, cf pgjdbc/pgjdbc#3565 more analysis in GEOS-11849
fixes access to a database behind a pgbouncer alias which doesn't match the real database name, cf pgjdbc/pgjdbc#3565 more analysis in GEOS-11849
fixes access to a database behind a pgbouncer alias which doesn't match the real database name, cf pgjdbc/pgjdbc#3565 more analysis in GEOS-11849
fixes access to a database behind a pgbouncer alias which doesn't match the real database name, cf pgjdbc/pgjdbc#3565 more analysis in GEOS-11849
No description provided.