apache/seatunnel · error · DatabaseAlreadyExistException
Database ${databaseName} already exists in catalog hive
Error message
Database ${databaseName} already exists in catalog hive What it means
Thrown by HiveMetaStoreCatalog.createDatabase when a database already exists in the Hive Metastore and ignoreIfExists=false. The underlying Thrift client raises AlreadyExistsException, which is translated into SeaTunnel's DatabaseAlreadyExistException. It prevents silent overwrite of an existing catalog namespace.
Source
Thrown at seatunnel-connectors-v2/connector-hive/src/main/java/org/apache/seatunnel/connectors/seatunnel/hive/utils/HiveMetaStoreCatalog.java:668
@Override
public void dropTable(TablePath tablePath, boolean ignoreIfNotExists)
throws TableNotExistException, CatalogException {
if (!tableExists(tablePath) && !ignoreIfNotExists) {
throw new TableNotExistException("hive", tablePath);
}
if (tableExists(tablePath)) {
dropTable(tablePath.getDatabaseName(), tablePath.getTableName());
}
}
@Override
public void createDatabase(TablePath tablePath, boolean ignoreIfExists)
throws DatabaseAlreadyExistException, CatalogException {
try {
createDatabaseIfNotExists(tablePath.getDatabaseName());
} catch (TException e) {
if (e instanceof AlreadyExistsException && !ignoreIfExists) {
throw new DatabaseAlreadyExistException("hive", tablePath.getDatabaseName());
}
throw new CatalogException(
"Failed to create database: " + tablePath.getDatabaseName(), e);
}
}
@Override
public void dropDatabase(TablePath tablePath, boolean ignoreIfNotExists)
throws DatabaseNotExistException, CatalogException {
try {
if (!databaseExists(tablePath.getDatabaseName()) && !ignoreIfNotExists) {
throw new DatabaseNotExistException("hive", tablePath.getDatabaseName());
}
if (databaseExists(tablePath.getDatabaseName())) {
getClient().dropDatabase(tablePath.getDatabaseName());
}
} catch (TException e) {
throw new CatalogException(View on GitHub (pinned to cf67b549a7)
Solutions
- Pass ignoreIfExists=true to createDatabase if overwriting/existing is acceptable
- Check databaseExists(tablePath) before calling createDatabase and skip when true
- Drop the existing database if it is no longer needed, or use a different database name
- Verify you are connected to the intended metastore (check hive-site.xml / metastore URIs)
Example fix
// before catalog.createDatabase(tablePath, false); // after catalog.createDatabase(tablePath, true); // or check catalog.databaseExists(tablePath) first
Defensive patterns
Strategy: try-catch
Validate before calling
if (catalog.databaseExists(tablePath)) { /* skip create */ } Type guard
boolean dbMissing = !catalog.databaseExists(tablePath);
Try / catch
try { catalog.createDatabase(tablePath, ignoreIfExists); } catch (DatabaseAlreadyExistException e) { log.warn("db {} already exists", tablePath.getDatabaseName()); } Prevention
- Prefer ignoreIfExists=true for idempotent pipelines
- Check databaseExists before DDL
- Use unique database names per environment/job
- Pin the correct hive-site.xml/metastore for the target cluster
When it happens
Trigger: Calling catalog.createDatabase(tablePath, ignoreIfExists=false) when the database name already exists in Hive; also any create path that internally calls createDatabaseIfNotExists while the metastore already holds the database.
Common situations: Re-running a job or DDL script after a previous successful run created the database; multiple jobs racing to create the same database; wrong hive conf.dir pointing at a metastore where the database already exists.
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
- Failed to open Hive catalog
- Failed to list databases
- Database ${databaseName} does not exist in catalog hive
- Failed to list tables in database: ${databaseName}
- Table ${tablePath} does not exist in catalog hive
AI-assisted analysis of apache/seatunnel@cf67b549a7 (2026-09-10).
Data as JSON: /api/errors/b8fedf67a3364670.
Report an issue: GitHub.