prestodb/presto · error · PrestoException
HIVE_METASTORE_ERROR
HIVE_METASTORE_ERROR
Error message
Database can not be created with a location set
What it means
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.
Source
Thrown at presto-hive-metastore/src/main/java/com/facebook/presto/hive/metastore/file/FileHiveMetastore.java:179
{
this.hdfsEnvironment = requireNonNull(hdfsEnvironment, "hdfsEnvironment is null");
this.catalogDirectory = new Path(requireNonNull(catalogDirectory, "baseDirectory is null"));
this.hdfsContext = new HdfsContext(new ConnectorIdentity(metastoreUser, Optional.empty(), Optional.empty()));
try {
metadataFileSystem = hdfsEnvironment.getFileSystem(hdfsContext, this.catalogDirectory);
}
catch (IOException e) {
throw new PrestoException(HIVE_METASTORE_ERROR, e);
}
}
@Override
public synchronized void createDatabase(MetastoreContext metastoreContext, Database database)
{
requireNonNull(database, "database is null");
if (database.getLocation().isPresent()) {
throw new PrestoException(HIVE_METASTORE_ERROR, "Database can not be created with a location set");
}
verifyDatabaseNotExists(metastoreContext, database.getDatabaseName());
Path databaseMetadataDirectory = getDatabaseMetadataDirectory(database.getDatabaseName());
writeSchemaFile("database", databaseMetadataDirectory, databaseCodec, new DatabaseMetadata(database), false);
}
@Override
public synchronized void dropDatabase(MetastoreContext metastoreContext, String databaseName)
{
requireNonNull(databaseName, "databaseName is null");
getRequiredDatabase(metastoreContext, databaseName);
if (!getAllTables(metastoreContext, databaseName).orElse(ImmutableList.of()).isEmpty()) {
throw new PrestoException(HIVE_METASTORE_ERROR, "Database " + databaseName + " is not empty");
}
View on GitHub (pinned to 55bb57d202)
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
Example fix
// before CREATE SCHEMA web WITH (location = 'hdfs:///warehouse/web'); // after (file metastore) CREATE SCHEMA web;
Defensive patterns
Strategy: validation
Validate before calling
// Before createDatabase on a file metastore
if (database.getLocation().isPresent()) {
// strip location or use a different metastore implementation
database = Database.builder(database).setLocation(Optional.empty()).build();
} Type guard
boolean isFileMetastoreCompatible(Database db) {
return db.getLocation().isEmpty();
} Try / catch
try {
metastore.createDatabase(metastoreContext, database);
} catch (PrestoException e) {
if (e.getErrorCode().getName().equals("HIVE_METASTORE_ERROR")) {
// retry without location, or switch to thrift/glue metastore
}
throw e;
} Prevention
- 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
When it happens
Trigger: Calling metastore.createDatabase(metastoreContext, database) where database.getLocation().isPresent() — e.g. CREATE SCHEMA ... WITH (location = '...') against a connector configured with hive.metastore=file.
Common situations: 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.
Related errors
- HIVE_DATABASE_LOCATION_ERROR
- NOT_SUPPORTED
- Table not found: ${databaseName}.${tableName}
- Table not found
- Constraint not found
AI-assisted analysis of prestodb/presto@55bb57d202 (2026-09-04).
Data as JSON: /api/errors/fbb637144be18704.
Report an issue: GitHub.