From a62fe3c88506b84f3c3b78987fa593b6022a2abc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sylvain=20Veyri=C3=A9?= Date: Thu, 25 Mar 2021 10:19:02 +0100 Subject: [PATCH] [BEAM-12044] JdbcIO read: always force autocommit to false --- .../src/main/java/org/apache/beam/sdk/io/jdbc/JdbcIO.java | 4 ++++ 1 file changed, 4 insertions(+) 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 93b0d393f3a0..d220679dab62 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 @@ -903,6 +903,10 @@ public void processElement(ProcessContext context) throws Exception { if (connection == null) { connection = dataSource.getConnection(); } + // PostgreSQL requires autocommit to be disabled to enable cursor streaming + // see https://jdbc.postgresql.org/documentation/head/query.html#query-with-cursor + LOG.info("Autocommit has been disabled"); + connection.setAutoCommit(false); try (PreparedStatement statement = connection.prepareStatement( query.get(), ResultSet.TYPE_FORWARD_ONLY, ResultSet.CONCUR_READ_ONLY)) {