apache/seatunnel · error · SeaTunnelException
JDBC connection fails to commit: ${e.getMessage()}
Error message
JDBC connection fails to commit: ${e.getMessage()} What it means
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.
Source
Thrown at seatunnel-connectors-v2/connector-cdc/connector-cdc-postgres/src/main/java/org/apache/seatunnel/connectors/seatunnel/cdc/postgres/utils/PostgresUtils.java:310
return new LsnOffset(offsetStrMap);
}
/** Fetch current largest log sequence number (LSN) of the database. */
public static LsnOffset currentLsn(PostgresConnection jdbcConnection) {
Long lsn;
Long txId;
try {
lsn = jdbcConnection.currentXLogLocation();
txId = jdbcConnection.currentTransactionId();
log.trace("Read xlogStart at '{}' from transaction '{}'", Lsn.valueOf(lsn), txId);
} catch (SQLException e) {
throw new SeaTunnelException("Error getting current Lsn/txId " + e.getMessage(), e);
}
try {
jdbcConnection.commit();
} catch (SQLException e) {
throw new SeaTunnelException("JDBC connection fails to commit: " + e.getMessage(), e);
}
Map<String, String> offsetMap = new HashMap<>();
offsetMap.put(SourceInfo.LSN_KEY, lsn.toString());
if (txId != null) {
offsetMap.put(SourceInfo.TXID_KEY, txId.toString());
}
offsetMap.put(
SourceInfo.TIMESTAMP_USEC_KEY,
String.valueOf(Conversions.toEpochMicros(Instant.MIN)));
return LsnOffset.of(offsetMap);
}
/** Get split scan query for the given table. */
public static String buildSplitScanQuery(
Table table, SeaTunnelRowType rowType, boolean isFirstSplit, boolean isLastSplit) {
return buildSplitQuery(table, rowType, isFirstSplit, isLastSplit, -1, true);
}View on GitHub (pinned to cf67b549a7)
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')
Example fix
// before
Offset offset = PostgresUtils.currentLsn(oldSharedConnection);
// after
JdbcConnection conn = dialect.openJdbcConnection(sourceConfig);
try {
if (!conn.connection().isValid(5)) {
conn = dialect.openJdbcConnection(sourceConfig); // fresh connection
}
Offset offset = PostgresUtils.currentLsn(conn);
} finally {
conn.close();
} Defensive patterns
Strategy: try-catch
Validate before calling
if (!conn.connection().isValid(5)) { conn = reopenConnection(); }
// also ensure no prior statement failed: conn.connection().getAutoCommit() state is clean Try / catch
try {
offset = PostgresUtils.currentLsn(conn);
} catch (SeaTunnelException e) {
LOG.error("commit failed while reading LSN", e);
conn = reopenConnection(); // retry once with fresh connection
offset = PostgresUtils.currentLsn(conn);
} Prevention
- 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
When it happens
Trigger: 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().
Common situations: 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.
Related errors
- Couldn't get timestamp utils from underlying connection
- Failed to discover remaining tables to capture
- Error to check tables:
- Failed to disable auto commit for Db2 CDC connection
- Couldn't obtain encoding for database <database>
AI-assisted analysis of apache/seatunnel@cf67b549a7 (2026-09-10).
Data as JSON: /api/errors/661083d298b9df81.
Report an issue: GitHub.