{"record":{"id":"b872ac08b36db64f","repo":"apache/seatunnel","slug":"database-already-existed","errorCode":"DATABASE_ALREADY_EXISTED","errorMessage":"Database %s already exist in Catalog %s.","messagePattern":"Database (.+?) already exist in Catalog (.+?)\\.","errorType":"error_code","errorClass":"DatabaseAlreadyExistException","httpStatus":null,"severity":"error","filePath":"seatunnel-connectors-v2/connector-jdbc/src/main/java/org/apache/seatunnel/connectors/seatunnel/jdbc/catalog/AbstractJdbcCatalog.java","lineNumber":555,"sourceCode":"            // Will there exist concurrent drop for one table?\n            executeInternal(dbUrl, getDropTableSql(tablePath));\n        } catch (SQLException e) {\n            throw new CatalogException(\n                    String.format(\"Failed dropping table %s\", tablePath.getFullName()), e);\n        }\n    }\n\n    @Override\n    public void createDatabase(TablePath tablePath, boolean ignoreIfExists)\n            throws DatabaseAlreadyExistException, CatalogException {\n        checkNotNull(tablePath, \"Table path cannot be null\");\n        checkNotNull(tablePath.getDatabaseName(), \"Database name cannot be null\");\n\n        if (databaseExists(tablePath.getDatabaseName())) {\n            if (ignoreIfExists) {\n                return;\n            }\n            throw new DatabaseAlreadyExistException(catalogName, tablePath.getDatabaseName());\n        }\n\n        createDatabaseInternal(tablePath.getDatabaseName());\n    }\n\n    protected String getCreateDatabaseSql(String databaseName) {\n        throw new UnsupportedOperationException();\n    }\n\n    protected void createDatabaseInternal(String databaseName) {\n        try {\n            executeInternal(defaultUrl, getCreateDatabaseSql(databaseName));\n        } catch (Exception e) {\n            throw new CatalogException(\n                    String.format(\n                            \"Failed creating database %s in catalog %s\",\n                            databaseName, this.catalogName),\n                    e);","sourceCodeStart":537,"sourceCodeEnd":573,"githubUrl":"https://github.com/apache/seatunnel/blob/cf67b549a7a6c35fa0beb12d83c62892427ea919/seatunnel-connectors-v2/connector-jdbc/src/main/java/org/apache/seatunnel/connectors/seatunnel/jdbc/catalog/AbstractJdbcCatalog.java#L537-L573","documentation":"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.","triggerScenarios":"Calling catalog.createDatabase(tablePath, false) when databaseExists(tablePath.getDatabaseName()) returns true.","commonSituations":"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.","solutions":["Pass ignoreIfExists=true if creation should be idempotent.","Check existence first with catalog.databaseExists(name) and skip creation.","Use a unique database name per environment/job if isolation is intended.","Remove the leftover database manually if it should not exist."],"exampleFix":"// before\ncatalog.createDatabase(TablePath.of(\"mydb\"), false);\n// after\ncatalog.createDatabase(TablePath.of(\"mydb\"), true);","handlingStrategy":"validation","validationCode":"if (catalog.databaseExists(dbName)) { /* skip or log */ } else { catalog.createDatabase(TablePath.of(dbName), false); }","typeGuard":null,"tryCatchPattern":"try { catalog.createDatabase(path, false); } catch (DatabaseAlreadyExistException e) { LOG.info(\"Database {} already exists\", dbName); }","preventionTips":["Use ignoreIfExists=true in setup scripts","Guard creation with databaseExists","Use environment-unique database names"],"tags":["jdbc","catalog","duplicate","database"],"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-23T08:17:48.524Z"}