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
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
9 changes: 9 additions & 0 deletions appveyor.yml
Expand Up @@ -76,6 +76,15 @@ build_script:
test_script:
- echo redirect escape ^> foo.bar
- echo privilegedPassword=Password12!>c:\projects\pgjdbc\build.local.properties
- set PGDATABASE=
- set PGHOST=
- set PGPASSFILE=
- set PGPASSWORD=
- set PGPORT=
- set PGSERVICE=
- set PGSERVICEFILE=
- set PGSYSCONFDIR=
- set PGUSER=
- gradlew test

cache:
Expand Down
14 changes: 14 additions & 0 deletions pgjdbc/src/main/java/org/postgresql/PGProperty.java
Expand Up @@ -223,6 +223,20 @@ public enum PGProperty {
false,
new String[] {"select", "callIfNoReturn", "call"}),

/**
* Group startup parameters in a transaction
* This is important in pool-by-transaction scenarios in order to make sure that all the statements
* reaches the same connection that is being initialized. All of the startup parameters will be wrapped
* in a transaction
* Note this is off by default as pgbouncer in statement mode
*/
GROUP_STARTUP_PARAMETERS(
"groupStartupParameters",
"false",
"This is important in pool-by-transaction scenarios in order to make sure that all "
+ "the statements reaches the same connection that is being initialized."
),

GSS_ENC_MODE(
"gssEncMode",
"allow",
Expand Down
Expand Up @@ -852,7 +852,7 @@ private void runInitialQueries(QueryExecutor queryExecutor, Properties info)

final int dbVersion = queryExecutor.getServerVersionNum();

if (dbVersion >= ServerVersion.v9_0.getVersionNum()) {
if (PGProperty.GROUP_STARTUP_PARAMETERS.getBoolean(info) && dbVersion >= ServerVersion.v9_0.getVersionNum()) {
SetupQueryRunner.run(queryExecutor, "BEGIN", false);
}

Expand All @@ -869,7 +869,7 @@ private void runInitialQueries(QueryExecutor queryExecutor, Properties info)
SetupQueryRunner.run(queryExecutor, sql.toString(), false);
}

if (dbVersion >= ServerVersion.v9_0.getVersionNum()) {
if (PGProperty.GROUP_STARTUP_PARAMETERS.getBoolean(info) && dbVersion >= ServerVersion.v9_0.getVersionNum()) {
SetupQueryRunner.run(queryExecutor, "COMMIT", false);
}
}
Expand Down
20 changes: 20 additions & 0 deletions pgjdbc/src/main/java/org/postgresql/ds/common/BaseDataSource.java
Expand Up @@ -1015,6 +1015,26 @@ public void setAssumeMinServerVersion(@Nullable String minVersion) {
PGProperty.ASSUME_MIN_SERVER_VERSION.set(properties, minVersion);
}

/**
* This is important in pool-by-transaction scenarios in order to make sure that all the statements
* reaches the same connection that is being initialized. If set then we will group the startup
* parameters in a transaction
* @return whether to group starup parameters or not
* @see PGProperty#GROUP_STARTUP_PARAMETERS
*/
public boolean getGroupStartupParameters() {
return PGProperty.GROUP_STARTUP_PARAMETERS.getBoolean(properties);
}

/**
*
* @param groupStartupParameters whether to group startup Parameters in a transaction or not
* @see PGProperty#GROUP_STARTUP_PARAMETERS
*/
public void setGroupStartupParameters(boolean groupStartupParameters) {
PGProperty.GROUP_STARTUP_PARAMETERS.set(properties, groupStartupParameters);
}

/**
* @return JAAS application name
* @see PGProperty#JAAS_APPLICATION_NAME
Expand Down