apache/seatunnel · error · DatabaseAlreadyExistException

DATABASE_ALREADY_EXISTED

DATABASE_ALREADY_EXISTED

Error message

Database %s already exist in Catalog %s.

What it means

DatabaseAlreadyExistException (code DATABASE_ALREADY_EXISTED) is thrown by createDatabase when the requested database already exists in this catalog and ignoreIfExists is false. The catalog checks databaseExists() before running the create DDL.

Solutions

  1. Pass ignoreIfExists=true if creation should be idempotent.
  2. Check existence first with catalog.databaseExists(name) and skip creation.
  3. Use a unique database name per environment/job if isolation is intended.
  4. Remove the leftover database manually if it should not exist.

Example fix

// before
catalog.createDatabase(TablePath.of("mydb"), false);
// after
catalog.createDatabase(TablePath.of("mydb"), true);
Defensive patterns

Strategy: validation

Validate before calling

if (catalog.databaseExists(dbName)) { /* skip or log */ } else { catalog.createDatabase(TablePath.of(dbName), false); }

Try / catch

try { catalog.createDatabase(path, false); } catch (DatabaseAlreadyExistException e) { LOG.info("Database {} already exists", dbName); }

Prevention

When it happens

Trigger: Calling catalog.createDatabase(tablePath, false) when databaseExists(tablePath.getDatabaseName()) returns true.

Common situations: Rerunning an idempotent setup script without ignoreIfExists=true; race where two jobs create the same database concurrently; catalog name/database name confusion across multiple catalogs.

Understand the failure class

Background: "already exists" / EEXIST / FileAlreadyExistsException: what the 'file already exists' error means and how to fix it — this error's family across 37 libraries.

Related errors


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

Appendix: source

Thrown at seatunnel-connectors-v2/connector-jdbc/src/main/java/org/apache/seatunnel/connectors/seatunnel/jdbc/catalog/AbstractJdbcCatalog.java:555

            // Will there exist concurrent drop for one table?
            executeInternal(dbUrl, getDropTableSql(tablePath));
        } catch (SQLException e) {
            throw new CatalogException(
                    String.format("Failed dropping table %s", tablePath.getFullName()), e);
        }
    }

    @Override
    public void createDatabase(TablePath tablePath, boolean ignoreIfExists)
            throws DatabaseAlreadyExistException, CatalogException {
        checkNotNull(tablePath, "Table path cannot be null");
        checkNotNull(tablePath.getDatabaseName(), "Database name cannot be null");

        if (databaseExists(tablePath.getDatabaseName())) {
            if (ignoreIfExists) {
                return;
            }
            throw new DatabaseAlreadyExistException(catalogName, tablePath.getDatabaseName());
        }

        createDatabaseInternal(tablePath.getDatabaseName());
    }

    protected String getCreateDatabaseSql(String databaseName) {
        throw new UnsupportedOperationException();
    }

    protected void createDatabaseInternal(String databaseName) {
        try {
            executeInternal(defaultUrl, getCreateDatabaseSql(databaseName));
        } catch (Exception e) {
            throw new CatalogException(
                    String.format(
                            "Failed creating database %s in catalog %s",
                            databaseName, this.catalogName),
                    e);

View on GitHub (pinned to cf67b549a7)