prestodb/presto · error · PrestoException
HIVE_DATABASE_LOCATION_ERROR
HIVE_DATABASE_LOCATION_ERROR
Error message
Database '%s' location is not set
What it means
getTableDefaultLocation derives a new table's default location from its parent database's location property in the metastore. If the database has no location set (empty or absent), Presto cannot determine where to place the table and throws HIVE_DATABASE_LOCATION_ERROR.
Source
Thrown at presto-hive/src/main/java/com/facebook/presto/hive/HiveWriteUtils.java:424
}
}
public static Path getTableDefaultLocation(ConnectorSession session, SemiTransactionalHiveMetastore metastore, HdfsEnvironment hdfsEnvironment, String schemaName, String tableName)
{
MetastoreContext metastoreContext = new MetastoreContext(
session.getIdentity(),
session.getQueryId(),
session.getClientInfo(),
session.getClientTags(),
session.getSource(),
getMetastoreHeaders(session),
isUserDefinedTypeEncodingEnabled(session),
metastore.getColumnConverterProvider(),
session.getWarningCollector(),
session.getRuntimeStats());
Optional<String> location = getDatabase(session.getIdentity(), metastoreContext, metastore, schemaName).getLocation();
if (!location.isPresent() || location.get().isEmpty()) {
throw new PrestoException(HIVE_DATABASE_LOCATION_ERROR, format("Database '%s' location is not set", schemaName));
}
HdfsContext context = new HdfsContext(session, schemaName, tableName, location.get(), true);
Path databasePath = new Path(location.get());
if (!isS3FileSystem(context, hdfsEnvironment, databasePath)) {
if (!pathExists(context, hdfsEnvironment, databasePath)) {
throw new PrestoException(HIVE_DATABASE_LOCATION_ERROR, format("Database '%s' location does not exist: %s", schemaName, databasePath));
}
if (!isDirectory(context, hdfsEnvironment, databasePath)) {
throw new PrestoException(HIVE_DATABASE_LOCATION_ERROR, format("Database '%s' location is not a directory: %s", schemaName, databasePath));
}
}
return new Path(databasePath, tableName);
}
private static Database getDatabase(ConnectorIdentity identity, MetastoreContext metastoreContext, SemiTransactionalHiveMetastore metastore, String database)
{View on GitHub (pinned to 55bb57d202)
Solutions
- Set the database location in the metastore: ALTER DATABASE schema SET LOCATION 'hdfs://.../schema' (Hive) or update the DBS.LOCATION_URI directly
- Create the table with an explicit external location: CREATE TABLE ... LOCATION '/explicit/path'
- Recreate the database with a valid LOCATION clause
Example fix
// before CREATE TABLE ghostdb.t (i int); -- ghostdb has no location // after ALTER DATABASE ghostdb SET LOCATION 'hdfs://nn/user/hive/warehouse/ghostdb.db'; CREATE TABLE ghostdb.t (i int);
Defensive patterns
Strategy: validation
Validate before calling
Database db = metastore.getDatabase(schema);
if (db.getLocation() == null || db.getLocation().isEmpty()) {
throw new IllegalStateException("Database has no location: " + schema);
} Try / catch
try {
createTable(schema, ...);
} catch (PrestoException e) {
if (e.getErrorCode() == HIVE_DATABASE_LOCATION_ERROR.toErrorCode()) {
// set the DB location or pass explicit LOCATION
} else throw e;
} Prevention
- Always create databases with an explicit LOCATION
- Validate DBS.LOCATION_URI after metastore migrations
- Use explicit table LOCATION for tables in databases managed by external tools
When it happens
Trigger: CREATE TABLE in a database whose metastore entry has no 'location' field populated — typical for databases created by non-Hive tools or manually inserted metastore rows.
Common situations: Databases created via custom metastore scripts lacking the location URI; corrupted metastore rows; databases migrated between metastore backends losing the location property.
Related errors
- HIVE_METASTORE_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/aaaf35d569098da1.
Report an issue: GitHub.