{"record":{"id":"6ff1591a30e6b2b6","repo":"apache/iceberg","slug":"can-not-alter-the-default-database-when-the-iceber-6ff159","errorCode":null,"errorMessage":"Can not alter the default database when the iceberg catalog doesn't support namespaces.","messagePattern":"Can not alter the default database when the iceberg catalog doesn't support namespaces\\.","errorType":"exception","errorClass":"CatalogException","httpStatus":null,"severity":"error","filePath":"flink/v2.3/flink/src/main/java/org/apache/iceberg/flink/FlinkCatalog.java","lineNumber":312,"sourceCode":"          }\n        }\n\n        if (!updates.isEmpty()) {\n          asNamespaceCatalog.setProperties(namespace, updates);\n        }\n\n        if (!removals.isEmpty()) {\n          asNamespaceCatalog.removeProperties(namespace, removals);\n        }\n\n      } catch (NoSuchNamespaceException e) {\n        if (!ignoreIfNotExists) {\n          throw new DatabaseNotExistException(getName(), name, e);\n        }\n      }\n    } else {\n      if (getDefaultDatabase().equals(name)) {\n        throw new CatalogException(\n            \"Can not alter the default database when the iceberg catalog doesn't support namespaces.\");\n      }\n      if (!ignoreIfNotExists) {\n        throw new DatabaseNotExistException(getName(), name);\n      }\n    }\n  }\n\n  @Override\n  public List<String> listTables(String databaseName)\n      throws DatabaseNotExistException, CatalogException {\n    try {\n      return icebergCatalog.listTables(appendLevel(baseNamespace, databaseName)).stream()\n          .map(TableIdentifier::name)\n          .collect(Collectors.toList());\n    } catch (NoSuchNamespaceException e) {\n      throw new DatabaseNotExistException(getName(), databaseName, e);\n    }","sourceCodeStart":294,"sourceCodeEnd":330,"githubUrl":"https://github.com/apache/iceberg/blob/86d9c8fc543e7c56c9f624eb725f76c9baff9570/flink/v2.3/flink/src/main/java/org/apache/iceberg/flink/FlinkCatalog.java#L294-L330","documentation":"When the wrapped Iceberg catalog does not support namespaces (asNamespaceCatalog == null), FlinkCatalog.alterDatabase rejects any attempt to alter the default database with a plain CatalogException, because database metadata cannot exist without namespace support. This is a hard guard, not influenced by ignoreIfNotExists.","triggerScenarios":"alterDatabase(getDefaultDatabase(), newDatabase, ignoreIfNotExists) on a catalog without namespace support — the guard getDefaultDatabase().equals(name) fires before anything else.","commonSituations":"Trying to set properties on the 'default' database of a limited Iceberg catalog backend; porting code written for Hive/Hadoop catalogs to a backend that only exposes the default DB; automated DDL scripts that alter all databases unconditionally.","solutions":["Skip altering the default database in scripts targeting catalogs without namespace support","Switch to a namespace-capable catalog backend (Hadoop/Hive/JDBC/REST) if database-level properties are required","Wrap the alter call so it filters out the default database before invoking","Store the desired metadata elsewhere (e.g. table-level properties) if the backend cannot hold DB properties"],"exampleFix":"// before\ncatalog.alterDatabase(catalog.getDefaultDatabase(), db, false); // CatalogException\n// after\nif (!catalog.getDefaultDatabase().equals(dbName)) {\n  catalog.alterDatabase(dbName, db, false);\n}","handlingStrategy":"validation","validationCode":"boolean isDefault = dbName.equals(defaultDatabase); // skip alter when true","typeGuard":"static boolean isAlterable(Catalog catalog, String dbName) {\n  return !dbName.equals(catalog.getDefaultDatabase());\n}","tryCatchPattern":"try {\n  catalog.alterDatabase(name, newDb, false);\n} catch (CatalogException e) {\n  LOG.warn(\"Default database cannot be altered on this catalog: {}\", e.getMessage());\n}","preventionTips":["Never target the default database for metadata changes on minimal backends","Filter out the default DB in bulk-alter scripts","Move DB-level metadata into table properties when namespace props are unsupported"],"tags":["flink","iceberg","catalog","default-database"],"backgroundTag":"unsupported-operation","analyzedSha":"86d9c8fc543e7c56c9f624eb725f76c9baff9570","analyzedAt":"2026-09-12T00:46:39.097Z","contentChangedAt":"2026-09-12T00:46:39.097Z","schemaVersion":2},"datasetVersion":"2026-09-14T16:17:12.679Z"}