From a464b453f3ee5d89147c57349f5b1dfffa2c2153 Mon Sep 17 00:00:00 2001 From: Vaibhav Kushwaha <34186745+vaibhav-yb@users.noreply.github.com> Date: Tue, 12 Nov 2024 15:49:31 +0530 Subject: [PATCH] [DBZ-PGYB] Set transaction isolation level before executing snapshot query (#164) This PR makes the changes to set the transaction isolation level to `SERIALIZABLE, READ ONLY, DEFERRABLE` before executing the snapshot read query. --- .../postgresql/PostgresSnapshotChangeEventSource.java | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/debezium-connector-postgres/src/main/java/io/debezium/connector/postgresql/PostgresSnapshotChangeEventSource.java b/debezium-connector-postgres/src/main/java/io/debezium/connector/postgresql/PostgresSnapshotChangeEventSource.java index ed247de8cbe..fc0924cf37d 100644 --- a/debezium-connector-postgres/src/main/java/io/debezium/connector/postgresql/PostgresSnapshotChangeEventSource.java +++ b/debezium-connector-postgres/src/main/java/io/debezium/connector/postgresql/PostgresSnapshotChangeEventSource.java @@ -293,6 +293,12 @@ protected void setSnapshotTransactionIsolationLevel(boolean isOnDemand) throws S } else { LOGGER.info("Skipping setting snapshot time, snapshot data will not be consistent"); } + + // Regardless of whether consistent snapshot is enabled or not, we need to set the + // transaction isolation level. + String transactionIsolationLevelStatement = "SET SESSION CHARACTERISTICS AS TRANSACTION ISOLATION LEVEL SERIALIZABLE, READ ONLY, DEFERRABLE;"; + LOGGER.info("Setting transaction isolation levels with statement {}", transactionIsolationLevelStatement); + jdbcConnection.executeWithoutCommitting(transactionIsolationLevelStatement); } /**