apache/seatunnel · error · CatalogException
Failed truncate table %s in catalog %s
Error message
Failed truncate table %s in catalog %s
What it means
CatalogException thrown by truncateTableInternal when executing the TRUNCATE TABLE statement fails with any exception. The message names the full table path and catalog; the cause holds the driver-level error.
Source
Thrown at seatunnel-connectors-v2/connector-jdbc/src/main/java/org/apache/seatunnel/connectors/seatunnel/jdbc/catalog/AbstractJdbcCatalog.java:695
// If sql is DDL, the execute() method always returns false, so the return value
// should not be used to determine whether changes were made in database.
protected boolean executeInternal(String url, String sql) throws SQLException {
LOG.info("Execute sql : {}", sql);
try (PreparedStatement ps = getConnection(url).prepareStatement(sql)) {
return ps.execute();
}
}
public CatalogTable getTable(String sqlQuery) throws SQLException {
Connection defaultConnection = getConnection(defaultUrl);
return CatalogUtils.getCatalogTable(defaultConnection, sqlQuery);
}
protected void truncateTableInternal(TablePath tablePath) throws CatalogException {
try {
executeInternal(defaultUrl, getTruncateTableSql(tablePath));
} catch (Exception e) {
throw new CatalogException(
String.format(
"Failed truncate table %s in catalog %s",
tablePath.getFullName(), this.catalogName),
e);
}
}
protected String getTruncateTableSql(TablePath tablePath) {
throw new UnsupportedOperationException();
}
protected String getExistDataSql(TablePath tablePath) {
throw new UnsupportedOperationException();
}
public void executeSql(TablePath tablePath, String sql) {
String dbUrl = getUrlFromDatabaseName(tablePath.getDatabaseName());
Connection connection = getConnection(dbUrl);View on GitHub (pinned to cf67b549a7)
Solutions
- Inspect the wrapped cause for the driver-level reason.
- Grant TRUNCATE/ALTER privileges to the catalog user.
- Remove or disable foreign keys referencing the table, or use DELETE FROM instead.
- Ensure no long-running transactions hold locks on the table.
- Verify getTruncateTableSql output against your DBMS syntax manually.
Example fix
// before
catalog.truncateTable(TablePath.of("db", "orders"), false); // FK referenced
// after
try (Connection conn = DriverManager.getConnection(url, user, pass);
Statement st = conn.createStatement()) {
st.execute("SET FOREIGN_KEY_CHECKS=0");
st.execute("TRUNCATE TABLE db.orders");
st.execute("SET FOREIGN_KEY_CHECKS=1");
} Defensive patterns
Strategy: try-catch
Validate before calling
if (!catalog.tableExists(tablePath)) return; // nothing to truncate
Try / catch
try { catalog.truncateTable(path, false); } catch (CatalogException e) { LOG.error("Truncate {} failed: {}", path.getFullName(), e.getCause(), e); } Prevention
- Ensure the user has TRUNCATE/ALTER privileges
- Check for FK references before truncating
- Avoid truncating tables under active transactions
- Verify getTruncateTableSql output for your DBMS dialect
When it happens
Trigger: catalog.truncateTable(tablePath, ignoreIfNotExists=false) on an existing table where executeInternal(defaultUrl, getTruncateTableSql(tablePath)) throws: TRUNCATE privilege missing, FK constraints referencing the table, table locked by active transactions, or unsupported truncate syntax.
Common situations: User has DML but not DDL/TRUNCATE rights; MySQL InnoDB table referenced by foreign keys (TRUNCATE fails where DELETE works); row locks from long-running readers/writers; dialect where getTruncateTableSql produces invalid SQL.
Related errors
- Truncate table failed
- Failed executeSql error %s
- Failed dropping table %s
- Failed creating database %s in catalog %s
- TABLE_NOT_EXISTED
AI-assisted analysis of apache/seatunnel@cf67b549a7 (2026-09-10).
Data as JSON: /api/errors/3c00e3e61657849f.
Report an issue: GitHub.