apache/seatunnel · info

Failed to get approximate row count from table status…

Error message

Failed to get approximate row count from table status, fallback to count rows

What it means

RedshiftDialect.approximateRowCntStatement first tries a fast approximate row count from Redshift's system table (STV_TBL_PERM). On SQLException, or when the query returns no rows, it logs this warning and falls back to an exact COUNT(*) on the table.

Solutions

  1. No action needed - it falls back to COUNT(*) automatically
  2. Grant the sync user SELECT on system tables (or elevated perms) to keep the fast path
  3. Verify the table exists/is visible to the user in Redshift

Example fix

null
Defensive patterns

Strategy: fallback

Try / catch

// behavior is already a fallback; just log-monitor
if (log.contains("fallback to count rows")) { /* consider granting STV_TBL_PERM access */ }

Prevention

When it happens

Trigger: SELECT from STV_TBL_PERM fails (permission denied, table absent from system view, transient connection error) during split enumeration for JDBC source on Redshift.

Common situations: User lacking access to Redshift system tables; recently created/renamed tables not yet in STV_TBL_PERM; transient cluster connectivity issues.

Understand the failure class

Background: "query failed", "%w: SQL error" — wrapped database query errors in Go libraries explained — this error's family across 3 libraries.

Related errors


AI-assisted analysis of apache/seatunnel@cf67b549a7 (2026-09-10). Data as JSON: /api/errors/6b20daec872f1134. Report an issue: GitHub.

Appendix: source

Thrown at seatunnel-connectors-v2/connector-jdbc/src/main/java/org/apache/seatunnel/connectors/seatunnel/jdbc/internal/dialect/redshift/RedshiftDialect.java:170

                                        .equals(table.getTablePath().getFullName()));
        if (useTableStats) {
            String rowCountQuery =
                    String.format(
                            "SELECT reltuples FROM pg_class r WHERE relkind = 'r' AND relname = '%s';",
                            table.getTablePath().getTableName());
            try (Statement stmt = connection.createStatement()) {
                log.info("Split Chunk, approximateRowCntStatement: {}", rowCountQuery);
                try (ResultSet rs = stmt.executeQuery(rowCountQuery)) {
                    if (!rs.next()) {
                        throw new SQLException(
                                String.format(
                                        "No result returned after running query [%s]",
                                        rowCountQuery));
                    }
                    return rs.getLong(1);
                }
            } catch (SQLException e) {
                log.warn(
                        "Failed to get approximate row count from table status, fallback to count rows",
                        e);
                return SQLUtils.countForTable(connection, tableIdentifier(table.getTablePath()));
            }
        }
        return SQLUtils.countForSubquery(connection, table.getQuery());
    }
}

View on GitHub (pinned to cf67b549a7)