{"record":{"id":"661083d298b9df81","repo":"apache/seatunnel","slug":"jdbc-connection-fails-to-commit-e-getmessage","errorCode":null,"errorMessage":"JDBC connection fails to commit: ${e.getMessage()}","messagePattern":"JDBC connection fails to commit: (.+?)","errorType":"exception","errorClass":"SeaTunnelException","httpStatus":null,"severity":"error","filePath":"seatunnel-connectors-v2/connector-cdc/connector-cdc-postgres/src/main/java/org/apache/seatunnel/connectors/seatunnel/cdc/postgres/utils/PostgresUtils.java","lineNumber":310,"sourceCode":"        return new LsnOffset(offsetStrMap);\n    }\n\n    /** Fetch current largest log sequence number (LSN) of the database. */\n    public static LsnOffset currentLsn(PostgresConnection jdbcConnection) {\n        Long lsn;\n        Long txId;\n        try {\n            lsn = jdbcConnection.currentXLogLocation();\n            txId = jdbcConnection.currentTransactionId();\n            log.trace(\"Read xlogStart at '{}' from transaction '{}'\", Lsn.valueOf(lsn), txId);\n        } catch (SQLException e) {\n            throw new SeaTunnelException(\"Error getting current Lsn/txId \" + e.getMessage(), e);\n        }\n\n        try {\n            jdbcConnection.commit();\n        } catch (SQLException e) {\n            throw new SeaTunnelException(\"JDBC connection fails to commit: \" + e.getMessage(), e);\n        }\n\n        Map<String, String> offsetMap = new HashMap<>();\n        offsetMap.put(SourceInfo.LSN_KEY, lsn.toString());\n        if (txId != null) {\n            offsetMap.put(SourceInfo.TXID_KEY, txId.toString());\n        }\n        offsetMap.put(\n                SourceInfo.TIMESTAMP_USEC_KEY,\n                String.valueOf(Conversions.toEpochMicros(Instant.MIN)));\n        return LsnOffset.of(offsetMap);\n    }\n\n    /** Get split scan query for the given table. */\n    public static String buildSplitScanQuery(\n            Table table, SeaTunnelRowType rowType, boolean isFirstSplit, boolean isLastSplit) {\n        return buildSplitQuery(table, rowType, isFirstSplit, isLastSplit, -1, true);\n    }","sourceCodeStart":292,"sourceCodeEnd":328,"githubUrl":"https://github.com/apache/seatunnel/blob/cf67b549a7a6c35fa0beb12d83c62892427ea919/seatunnel-connectors-v2/connector-cdc/connector-cdc-postgres/src/main/java/org/apache/seatunnel/connectors/seatunnel/cdc/postgres/utils/PostgresUtils.java#L292-L328","documentation":"Thrown by PostgresUtils.currentLsn() when the JDBC connection used to fetch the current LSN/txId fails to commit the transaction that read pg_current_wal_lsn(). It wraps the underlying SQLException into a SeaTunnelException so the CDC reader fails fast instead of recording an invalid offset.","triggerScenarios":"Calling PostgresUtils.currentLsn(jdbcConnection) when the connection is broken (network drop, server restart, idle timeout), when the transaction is already aborted by a prior error, or when autocommit/state conflicts prevent commit().","commonSituations":"Long-running CDC jobs whose pooled connection was idle-killed by the firewall or Postgres; concurrent use of the same connection by another thread; Postgres 'current transaction is aborted' after a failed statement.","solutions":["Check the database is reachable and the connection is still valid before/while reading the LSN","Enable connection validation/keepalive on the JDBC pool so dead connections are evicted","Retry currentLsn() with a fresh connection instead of reusing a possibly aborted one","Review Postgres server logs for the SQLException cause (e.g. 'connection reset', 'aborted transaction')"],"exampleFix":"// before\nOffset offset = PostgresUtils.currentLsn(oldSharedConnection);\n// after\nJdbcConnection conn = dialect.openJdbcConnection(sourceConfig);\ntry {\n    if (!conn.connection().isValid(5)) {\n        conn = dialect.openJdbcConnection(sourceConfig); // fresh connection\n    }\n    Offset offset = PostgresUtils.currentLsn(conn);\n} finally {\n    conn.close();\n}","handlingStrategy":"try-catch","validationCode":"if (!conn.connection().isValid(5)) { conn = reopenConnection(); }\n// also ensure no prior statement failed: conn.connection().getAutoCommit() state is clean","typeGuard":null,"tryCatchPattern":"try {\n    offset = PostgresUtils.currentLsn(conn);\n} catch (SeaTunnelException e) {\n    LOG.error(\"commit failed while reading LSN\", e);\n    conn = reopenConnection(); // retry once with fresh connection\n    offset = PostgresUtils.currentLsn(conn);\n}","preventionTips":["Use connection validation/keepalive so dead pooled connections are never reused","Never share the JDBC connection across threads during offset reads","Retry LSN reads on a fresh connection after any transaction-aborting error","Monitor Postgres logs for connection resets and aborted transactions"],"tags":["jdbc","postgres","cdc","connection"],"backgroundTag":"database-write-failed","analyzedSha":"cf67b549a7a6c35fa0beb12d83c62892427ea919","analyzedAt":"2026-09-10T21:44:55.265Z","contentChangedAt":"2026-09-10T21:44:55.265Z","schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}