apache/dolphinscheduler · error · RuntimeException

Get current version from database error, sql: " + sql

Error message

Get current version from database error, sql: " + sql

What it means

UpgradeDao.getCurrentVersion runs 'select version from <versionName>' (t_ds_version) to read the installed schema version. A SQLException during that query is rethrown as RuntimeException 'Get current version from database error, sql: <sql>'. It means the version lookup query itself failed against the database.

Source

Thrown at dolphinscheduler-tools/src/main/java/org/apache/dolphinscheduler/tools/datasource/upgrader/UpgradeDao.java:83

        } catch (Exception ex) {
            throw new RuntimeException("Execute initialize sql file: " + sqlFilePath + " error", ex);
        }
    }

    public String getCurrentVersion(String versionName) {
        String sql = String.format("select version from %s", versionName);
        String version = null;
        try (
                Connection conn = dataSource.getConnection();
                PreparedStatement pstmt = conn.prepareStatement(sql);
                ResultSet rs = pstmt.executeQuery()) {
            if (rs.next()) {
                version = rs.getString(1);
            }
            return version;
        } catch (SQLException e) {
            log.error("Get current version from database error, sql: {}", sql, e);
            throw new RuntimeException("Get current version from database error, sql: " + sql, e);
        }
    }

    public void upgradeDolphinScheduler(String schemaDir) {
        upgradeDolphinSchedulerDDL(schemaDir, "dolphinscheduler_ddl.sql");
        upgradeDolphinSchedulerDML(schemaDir, "dolphinscheduler_dml.sql");
    }

    private void upgradeDolphinSchedulerDML(String schemaDir, String scriptFile) {
        String schemaVersion = schemaDir.split("_")[0];
        String sqlFilePath =
                String.format("sql/upgrade/%s/%s/%s", schemaDir, dbType.getDb(), scriptFile);
        try {
            // Execute the upgraded dolphinscheduler dml
            SqlScriptRunner sqlScriptRunner = new SqlScriptRunner(dataSource, sqlFilePath);
            sqlScriptRunner.execute();
            try (Connection connection = dataSource.getConnection()) {
                String upgradeSQL;

View on GitHub (pinned to 02eac45a1b)

Solutions

  1. Grant SELECT on t_ds_version to the database user used by the upgrade tool.
  2. Test the exact SQL manually with the same JDBC user: SELECT version FROM t_ds_version;
  3. Check DB connectivity (connection pool/timeout settings) and re-run the upgrade.
  4. Inspect the cause SQLException for the vendor error code to pinpoint permissions vs connection issues.
Defensive patterns

Strategy: retry

Validate before calling

// pre-check with the same connection/user
try (PreparedStatement ps = conn.prepareStatement("select version from t_ds_version");
     ResultSet rs = ps.executeQuery()) {
    if (!rs.next()) log.warn("t_ds_version has no rows");
}

Try / catch

try {
    String v = upgradeDao.getCurrentVersion("t_ds_version");
} catch (RuntimeException e) {
    if (e.getCause() instanceof SQLException) {
        log.error("Version query failed (check privileges/connection): {}", e.getCause().getMessage());
        // retry once after reconnect
    } else throw e;
}

Prevention

When it happens

Trigger: Calling getCurrentVersion when the query throws SQLException: the t_ds_version table exists check passed but the query still fails due to permissions, connection drop, wrong catalog/schema, or a driver issue.

Common situations: Insufficient SELECT privilege on the version table; stale/dropped connection to the DB during a long upgrade; connecting with a user whose default schema differs from the one holding t_ds_version.

Understand the failure class

Background: Database query failed: Internal Server Error 500s wrapping SQL, Prisma, and connection failures — what to check first — this error's family across 16 libraries.

Related errors


AI-assisted analysis of apache/dolphinscheduler@02eac45a1b (2026-09-06). Data as JSON: /api/errors/d559d9b39f742c0f. Report an issue: GitHub.