This is an automated email from the ASF dual-hosted git repository.

yhu pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/beam.git


The following commit(s) were added to refs/heads/master by this push:
     new f30aa9655d2 Fix JdbcIO.read log spam when autocommit disabled (#35825)
f30aa9655d2 is described below

commit f30aa9655d2758dcbce5db87fb3d9fd69246aee1
Author: Yi Hu <[email protected]>
AuthorDate: Fri Aug 8 15:52:33 2025 -0400

    Fix JdbcIO.read log spam when autocommit disabled (#35825)
---
 .../main/java/org/apache/beam/sdk/io/jdbc/JdbcIO.java   | 17 +++++++++--------
 1 file changed, 9 insertions(+), 8 deletions(-)

diff --git 
a/sdks/java/io/jdbc/src/main/java/org/apache/beam/sdk/io/jdbc/JdbcIO.java 
b/sdks/java/io/jdbc/src/main/java/org/apache/beam/sdk/io/jdbc/JdbcIO.java
index f075d5b7b6c..113d14dd238 100644
--- a/sdks/java/io/jdbc/src/main/java/org/apache/beam/sdk/io/jdbc/JdbcIO.java
+++ b/sdks/java/io/jdbc/src/main/java/org/apache/beam/sdk/io/jdbc/JdbcIO.java
@@ -1709,6 +1709,15 @@ public class JdbcIO {
         try {
           connection = validSource.getConnection();
           this.connection = connection;
+
+          // PostgreSQL requires autocommit to be disabled to enable cursor 
streaming
+          // see 
https://jdbc.postgresql.org/documentation/head/query.html#query-with-cursor
+          // This option is configurable as Informix will error
+          // if calling setAutoCommit on a non-logged database
+          if (disableAutoCommit) {
+            LOG.info("Autocommit has been disabled");
+            connection.setAutoCommit(false);
+          }
         } finally {
           connectionLock.unlock();
         }
@@ -1739,14 +1748,6 @@ public class JdbcIO {
     public void processElement(ProcessContext context) throws Exception {
       // Only acquire the connection if we need to perform a read.
       Connection connection = getConnection();
-      // PostgreSQL requires autocommit to be disabled to enable cursor 
streaming
-      // see 
https://jdbc.postgresql.org/documentation/head/query.html#query-with-cursor
-      // This option is configurable as Informix will error
-      // if calling setAutoCommit on a non-logged database
-      if (disableAutoCommit) {
-        LOG.info("Autocommit has been disabled");
-        connection.setAutoCommit(false);
-      }
       try (PreparedStatement statement =
           connection.prepareStatement(
               query.get(), ResultSet.TYPE_FORWARD_ONLY, 
ResultSet.CONCUR_READ_ONLY)) {

Reply via email to