{"record":{"id":"b8fedf67a3364670","repo":"apache/seatunnel","slug":"database-databasename-already-exists-in-catalog","errorCode":null,"errorMessage":"Database ${databaseName} already exists in catalog hive","messagePattern":"Database (.+?) already exists in catalog hive","errorType":"exception","errorClass":"DatabaseAlreadyExistException","httpStatus":null,"severity":"error","filePath":"seatunnel-connectors-v2/connector-hive/src/main/java/org/apache/seatunnel/connectors/seatunnel/hive/utils/HiveMetaStoreCatalog.java","lineNumber":668,"sourceCode":"    @Override\n    public void dropTable(TablePath tablePath, boolean ignoreIfNotExists)\n            throws TableNotExistException, CatalogException {\n        if (!tableExists(tablePath) && !ignoreIfNotExists) {\n            throw new TableNotExistException(\"hive\", tablePath);\n        }\n        if (tableExists(tablePath)) {\n            dropTable(tablePath.getDatabaseName(), tablePath.getTableName());\n        }\n    }\n\n    @Override\n    public void createDatabase(TablePath tablePath, boolean ignoreIfExists)\n            throws DatabaseAlreadyExistException, CatalogException {\n        try {\n            createDatabaseIfNotExists(tablePath.getDatabaseName());\n        } catch (TException e) {\n            if (e instanceof AlreadyExistsException && !ignoreIfExists) {\n                throw new DatabaseAlreadyExistException(\"hive\", tablePath.getDatabaseName());\n            }\n            throw new CatalogException(\n                    \"Failed to create database: \" + tablePath.getDatabaseName(), e);\n        }\n    }\n\n    @Override\n    public void dropDatabase(TablePath tablePath, boolean ignoreIfNotExists)\n            throws DatabaseNotExistException, CatalogException {\n        try {\n            if (!databaseExists(tablePath.getDatabaseName()) && !ignoreIfNotExists) {\n                throw new DatabaseNotExistException(\"hive\", tablePath.getDatabaseName());\n            }\n            if (databaseExists(tablePath.getDatabaseName())) {\n                getClient().dropDatabase(tablePath.getDatabaseName());\n            }\n        } catch (TException e) {\n            throw new CatalogException(","sourceCodeStart":650,"sourceCodeEnd":686,"githubUrl":"https://github.com/apache/seatunnel/blob/cf67b549a7a6c35fa0beb12d83c62892427ea919/seatunnel-connectors-v2/connector-hive/src/main/java/org/apache/seatunnel/connectors/seatunnel/hive/utils/HiveMetaStoreCatalog.java#L650-L686","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","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)"],"exampleFix":"// before\ncatalog.createDatabase(tablePath, false);\n// after\ncatalog.createDatabase(tablePath, true); // or check catalog.databaseExists(tablePath) first","handlingStrategy":"try-catch","validationCode":"if (catalog.databaseExists(tablePath)) { /* skip create */ }","typeGuard":"boolean dbMissing = !catalog.databaseExists(tablePath);","tryCatchPattern":"try { catalog.createDatabase(tablePath, ignoreIfExists); } catch (DatabaseAlreadyExistException e) { log.warn(\"db {} already exists\", tablePath.getDatabaseName()); }","preventionTips":["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"],"tags":["hive","catalog","database-exists"],"backgroundTag":"file-already-exists","analyzedSha":"cf67b549a7a6c35fa0beb12d83c62892427ea919","analyzedAt":"2026-09-10T21:44:55.265Z","contentChangedAt":"2026-09-10T21:44:55.265Z","schemaVersion":2},"datasetVersion":"2026-09-14T11:17:12.474Z"}