{"record":{"id":"fbb637144be18704","repo":"prestodb/presto","slug":"hive-metastore-error-fbb637","errorCode":"HIVE_METASTORE_ERROR","errorMessage":"Database can not be created with a location set","messagePattern":"Database can not be created with a location set","errorType":"error_code","errorClass":"PrestoException","httpStatus":null,"severity":"error","filePath":"presto-hive-metastore/src/main/java/com/facebook/presto/hive/metastore/file/FileHiveMetastore.java","lineNumber":179,"sourceCode":"    {\n        this.hdfsEnvironment = requireNonNull(hdfsEnvironment, \"hdfsEnvironment is null\");\n        this.catalogDirectory = new Path(requireNonNull(catalogDirectory, \"baseDirectory is null\"));\n        this.hdfsContext = new HdfsContext(new ConnectorIdentity(metastoreUser, Optional.empty(), Optional.empty()));\n        try {\n            metadataFileSystem = hdfsEnvironment.getFileSystem(hdfsContext, this.catalogDirectory);\n        }\n        catch (IOException e) {\n            throw new PrestoException(HIVE_METASTORE_ERROR, e);\n        }\n    }\n\n    @Override\n    public synchronized void createDatabase(MetastoreContext metastoreContext, Database database)\n    {\n        requireNonNull(database, \"database is null\");\n\n        if (database.getLocation().isPresent()) {\n            throw new PrestoException(HIVE_METASTORE_ERROR, \"Database can not be created with a location set\");\n        }\n\n        verifyDatabaseNotExists(metastoreContext, database.getDatabaseName());\n\n        Path databaseMetadataDirectory = getDatabaseMetadataDirectory(database.getDatabaseName());\n        writeSchemaFile(\"database\", databaseMetadataDirectory, databaseCodec, new DatabaseMetadata(database), false);\n    }\n\n    @Override\n    public synchronized void dropDatabase(MetastoreContext metastoreContext, String databaseName)\n    {\n        requireNonNull(databaseName, \"databaseName is null\");\n\n        getRequiredDatabase(metastoreContext, databaseName);\n        if (!getAllTables(metastoreContext, databaseName).orElse(ImmutableList.of()).isEmpty()) {\n            throw new PrestoException(HIVE_METASTORE_ERROR, \"Database \" + databaseName + \" is not empty\");\n        }\n","sourceCodeStart":161,"sourceCodeEnd":197,"githubUrl":"https://github.com/prestodb/presto/blob/55bb57d202de3b926896fa966c2c4a44c779634e/presto-hive-metastore/src/main/java/com/facebook/presto/hive/metastore/file/FileHiveMetastore.java#L161-L197","documentation":"FileHiveMetastore (file-based metastore backed by files on HDFS/local FS) rejects createDatabase calls when the Database object carries an explicit location, because database directories are derived deterministically via getDatabaseMetadataDirectory. Allowing arbitrary locations would break the metastore's layout invariants, so it throws HIVE_METASTORE_ERROR.","triggerScenarios":"Calling metastore.createDatabase(metastoreContext, database) where database.getLocation().isPresent() — e.g. CREATE SCHEMA ... WITH (location = '...') against a connector configured with hive.metastore=file.","commonSituations":"Users applying Hive-metastore-style CREATE SCHEMA WITH (location=...) syntax against a file-based metastore; deployment tooling that always sets a location property; switching a catalog from Thrift/Hive metastore to file metastore without removing location clauses.","solutions":["Remove the location property from the CREATE SCHEMA statement when using the file metastore","Switch the catalog to a Thrift or Glue metastore if custom database locations are required","Create the database without location and place data under table-level locations instead","Update deployment scripts/templates to omit location for file-metastore catalogs"],"exampleFix":"// before\nCREATE SCHEMA web WITH (location = 'hdfs:///warehouse/web');\n// after (file metastore)\nCREATE SCHEMA web;","handlingStrategy":"validation","validationCode":"// Before createDatabase on a file metastore\nif (database.getLocation().isPresent()) {\n    // strip location or use a different metastore implementation\n    database = Database.builder(database).setLocation(Optional.empty()).build();\n}","typeGuard":"boolean isFileMetastoreCompatible(Database db) {\n    return db.getLocation().isEmpty();\n}","tryCatchPattern":"try {\n    metastore.createDatabase(metastoreContext, database);\n} catch (PrestoException e) {\n    if (e.getErrorCode().getName().equals(\"HIVE_METASTORE_ERROR\")) {\n        // retry without location, or switch to thrift/glue metastore\n    }\n    throw e;\n}","preventionTips":["Omit location from CREATE SCHEMA on file-metastore catalogs","Document catalog metastore type in team runbooks so DDL matches backend","Use Thrift/Glue metastore when custom database locations are needed","Template DDL scripts per metastore implementation"],"tags":["hive","metastore","file-metastore","database","ddl"],"backgroundTag":"database-location-not-supported","analyzedSha":"55bb57d202de3b926896fa966c2c4a44c779634e","analyzedAt":"2026-09-04T12:50:26.162Z","contentChangedAt":"2026-09-04T12:50:26.162Z","schemaVersion":2},"datasetVersion":"2026-09-11T21:17:09.523Z"}