{"record":{"id":"5b2eec67ee718a23","repo":"apache/iceberg","slug":"cannot-create-namespace-s-because-it-already-exis","errorCode":null,"errorMessage":"Cannot create namespace %s because it already exists in Glue","messagePattern":"Cannot create namespace (.+?) because it already exists in Glue","errorType":"exception","errorClass":"AlreadyExistsException","httpStatus":null,"severity":"error","filePath":"aws/src/main/java/org/apache/iceberg/aws/glue/GlueCatalog.java","lineNumber":478,"sourceCode":"      throw e;\n    }\n\n    LOG.info(\"Successfully renamed table from {} to {}\", from, to);\n  }\n\n  @Override\n  public void createNamespace(Namespace namespace, Map<String, String> metadata) {\n    try {\n      glue.createDatabase(\n          CreateDatabaseRequest.builder()\n              .catalogId(awsProperties.glueCatalogId())\n              .databaseInput(\n                  IcebergToGlueConverter.toDatabaseInput(\n                      namespace, metadata, awsProperties.glueCatalogSkipNameValidation()))\n              .build());\n      LOG.info(\"Created namespace: {}\", namespace);\n    } catch (software.amazon.awssdk.services.glue.model.AlreadyExistsException e) {\n      throw new AlreadyExistsException(\n          \"Cannot create namespace %s because it already exists in Glue\", namespace);\n    }\n  }\n\n  @Override\n  public List<Namespace> listNamespaces(Namespace namespace) throws NoSuchNamespaceException {\n    if (!namespace.isEmpty()) {\n      // if it is not a list all op, just check if the namespace exists and return empty.\n      if (namespaceExists(namespace)) {\n        return Lists.newArrayList();\n      }\n      throw new NoSuchNamespaceException(\n          \"Glue does not support nested namespace, cannot list namespaces under %s\", namespace);\n    }\n\n    // should be safe to list all before returning the list, instead of dynamically load the list.\n    String nextToken = null;\n    List<Namespace> results = Lists.newArrayList();","sourceCodeStart":460,"sourceCodeEnd":496,"githubUrl":"https://github.com/apache/iceberg/blob/86d9c8fc543e7c56c9f624eb725f76c9baff9570/aws/src/main/java/org/apache/iceberg/aws/glue/GlueCatalog.java#L460-L496","documentation":"GlueCatalog.createNamespace throws AlreadyExistsException when Glue's CreateDatabase responds with AlreadyExistsException, i.e. a Glue database with the same name already exists. The library surfaces it because namespaces are unique within a catalog and creating a duplicate would silently overwrite nothing but signals a caller logic problem.","triggerScenarios":"Calling catalog.createNamespace(Namespace.of(\"db\"), props) when Glue already contains a database named `db`; running idempotent setup scripts twice; two concurrent jobs both creating the same namespace.","commonSituations":"Initialization scripts that don't check existence first; re-running a failed pipeline from scratch; environment cloning where the namespace was created out-of-band in the AWS console; races between parallel deployments.","solutions":["Check `catalog.namespaceExists(namespace)` before calling createNamespace, or treat AlreadyExistsException as success in idempotent setup code.","Use a create-if-not-exists pattern: catch AlreadyExistsException and continue instead of failing the job.","Verify you are pointing at the intended Glue catalog ID/region — the name may already exist in the wrong environment.","If the existing namespace has wrong metadata, drop and recreate it explicitly rather than relying on create."],"exampleFix":"// before\ncatalog.createNamespace(Namespace.of(\"analytics\"), props);\n\n// after\nNamespace ns = Namespace.of(\"analytics\");\nif (!catalog.namespaceExists(ns)) {\n  catalog.createNamespace(ns, props);\n}","handlingStrategy":"try-catch","validationCode":"Namespace ns = Namespace.of(\"analytics\");\nif (catalog.namespaceExists(ns)) {\n  LOG.info(\"Namespace already exists, skipping create\");\n}","typeGuard":null,"tryCatchPattern":"try {\n  catalog.createNamespace(ns, props);\n} catch (AlreadyExistsException e) {\n  LOG.info(\"Namespace {} already exists, treating as success\", ns);\n}","preventionTips":["Make setup scripts idempotent: check namespaceExists or catch AlreadyExistsException","Use one owner (single job) for namespace creation in shared environments","Confirm the target Glue catalog ID/region before creating namespaces"],"tags":["aws","glue","namespace","already-exists"],"backgroundTag":"file-already-exists","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"}