Skip to content

Commit

Permalink
fix: added GROUP_STARTUP_PARAMETERS boolean property to determine whe…
Browse files Browse the repository at this point in the history
…ther or not to group startup parameters in a transaction or not fixes Issue 2423 pgbouncer cannot deal with transactions in statement pooling mode (#2425)

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

* unset environment variables before running tests
  • Loading branch information
davecramer committed Jun 8, 2022
1 parent a76991e commit 45f9b93
Show file tree
Hide file tree
Showing 4 changed files with 45 additions and 2 deletions.
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 @@ -863,7 +863,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 @@ -880,7 +880,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

0 comments on commit 45f9b93

Please sign in to comment.