Skip to content
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

fix: added GROUP_STARTUP_PARAMETERS boolean property to determine whether or not to group startup parameters in a transaction or not fixes Issue 2423 pgbouncer cannot deal with transactions in statement pooling mode #2425

Merged
merged 2 commits into from Jun 8, 2022

Conversation

davecramer
Copy link
Member

@davecramer davecramer commented Jan 27, 2022

fixes Issue #2423

…ther or not to group startup parameters in a transaction or not fixes Issue 2423 pgbouncer cannot deal with transactions in statement pooling mode
@jesperpedersen
Copy link
Contributor

I think it should be the other way around - e.g. true.

Executing statements assume auto-commit per statement unless an explicit transaction is started.

If "statement pooling" doesn't respect that - a transaction can be started on one connection and each of the "body" statement executed on another (or more) plus finally the commit on a third connection - then users need to explicit set this property to false.

Connection pools looks at the Z message in order to identify the transaction state of a connection - grouping statements inside a transaction from a single client is critical to both initialize and execute work-loads.

@davecramer
Copy link
Member Author

Hmmm the idea is that your PR is a "new" behaviour and would have to be requested.

Good question for discussion though

@jesperpedersen
Copy link
Contributor

I understand that.

However, "statement pooling" assumes auto-commit ALWAYS and SELECT ONLY as ANY transaction semantics is disabled. This is one of the reasons why @pgagroal won't support this mode, as people need to really understand the underlying constraints. Once you code to those constraints transaction pooling will give you the same performance and architecture.

@davecramer
Copy link
Member Author

hmmm... interesting as ANY transaction semantics is disabled. Every statement in postgres is a transaction. So are you saying you can't do an insert in a single statement ?

@jesperpedersen
Copy link
Contributor

From a user level.

Having BEGIN + COMMIT/ROLLBACK around your functionality is very different than having it without.

Sure , in JDBC you have to do

c.setAutoCommit(false);
...
c.commit();

and so on, but in practice a transaction manager will handle that for you transparently.

This PR is only to group the startup statements, not to change the overall driver behaviour - which would be dangerous.

@davecramer
Copy link
Member Author

So you are referring to user level transactions, not "actual transactions"

@jesperpedersen
Copy link
Contributor

If this PR is merged with false as the default you should probably bump the minor version to 42.4, as it is a behaviour change from 42.3.

@hannibal218bc
Copy link

Thank you @davecramer for the quick PR.
Is there something I could contribute to move forward with this?

(I'd be happy with any of the defaults. I agree that statement-level pooling is an advanced configuration and whoever employs that should be able to RTFM and set the appropriate parameter. On the other hand, I'd find it surprising if you need to RTFM and set an appropriate parameter to use pgbouncer with pgjdbc.)

Furthermore, I have still not understood what the original PR is actually supposed to deliver. In a transaction pool, the effects of SET ... will be reverted anyways at the end of the transaction, and I did not find any evidence of pgbouncer saving a client's SET ... commands to be replayed when re-connecting to the next backend on a subsequent connection. Yes, it will replay the startup parameters, but SET ... is no such parameter as far as I can tell? So I'm thinking the backend will run 'DISCARD ALL;' immediately after the new commit, so there won't be any effect at all?
YMMV by reset_query or other poolers ...

Thanks again for all of your ongoing efforts in this project!

@davecramer
Copy link
Member Author

@hannibal218bc we've been a little distracted by the latest security advisory.

@jesperpedersen care to expound on the use case. My understanding is that it ensures that the startup parameters are all applied to the same connection ?

@hannibal218bc
Copy link

@davecramer may I again ask if there is anything we can help to get this issue resolved? The issue is still present in the latest 42.3.4 release. Thanks!

@vlsi
Copy link
Member

vlsi commented Jun 8, 2022

I think the PR is good to go, except I would add a relevant notice to the changelog like «revert to … behaviour, do not group startup parameters in a transaction, …»

@davecramer
Copy link
Member Author

Alternatively we bump to 42.4.0 ?

@vlsi vlsi added this to the 44.4 milestone Jun 8, 2022
@vlsi
Copy link
Member

vlsi commented Jun 8, 2022

Sure. Let's merge it, bump the version and proceed with the release.

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

Successfully merging this pull request may close these issues.

Grouping of startup statements broke "statement" pooling
4 participants