{"record":{"id":"aaaf35d569098da1","repo":"prestodb/presto","slug":"hive-database-location-error","errorCode":"HIVE_DATABASE_LOCATION_ERROR","errorMessage":"Database '%s' location is not set","messagePattern":"Database '(.+?)' location is not set","errorType":"error_code","errorClass":"PrestoException","httpStatus":null,"severity":"error","filePath":"presto-hive/src/main/java/com/facebook/presto/hive/HiveWriteUtils.java","lineNumber":424,"sourceCode":"        }\n    }\n\n    public static Path getTableDefaultLocation(ConnectorSession session, SemiTransactionalHiveMetastore metastore, HdfsEnvironment hdfsEnvironment, String schemaName, String tableName)\n    {\n        MetastoreContext metastoreContext = new MetastoreContext(\n                session.getIdentity(),\n                session.getQueryId(),\n                session.getClientInfo(),\n                session.getClientTags(),\n                session.getSource(),\n                getMetastoreHeaders(session),\n                isUserDefinedTypeEncodingEnabled(session),\n                metastore.getColumnConverterProvider(),\n                session.getWarningCollector(),\n                session.getRuntimeStats());\n        Optional<String> location = getDatabase(session.getIdentity(), metastoreContext, metastore, schemaName).getLocation();\n        if (!location.isPresent() || location.get().isEmpty()) {\n            throw new PrestoException(HIVE_DATABASE_LOCATION_ERROR, format(\"Database '%s' location is not set\", schemaName));\n        }\n\n        HdfsContext context = new HdfsContext(session, schemaName, tableName, location.get(), true);\n        Path databasePath = new Path(location.get());\n        if (!isS3FileSystem(context, hdfsEnvironment, databasePath)) {\n            if (!pathExists(context, hdfsEnvironment, databasePath)) {\n                throw new PrestoException(HIVE_DATABASE_LOCATION_ERROR, format(\"Database '%s' location does not exist: %s\", schemaName, databasePath));\n            }\n            if (!isDirectory(context, hdfsEnvironment, databasePath)) {\n                throw new PrestoException(HIVE_DATABASE_LOCATION_ERROR, format(\"Database '%s' location is not a directory: %s\", schemaName, databasePath));\n            }\n        }\n\n        return new Path(databasePath, tableName);\n    }\n\n    private static Database getDatabase(ConnectorIdentity identity, MetastoreContext metastoreContext, SemiTransactionalHiveMetastore metastore, String database)\n    {","sourceCodeStart":406,"sourceCodeEnd":442,"githubUrl":"https://github.com/prestodb/presto/blob/55bb57d202de3b926896fa966c2c4a44c779634e/presto-hive/src/main/java/com/facebook/presto/hive/HiveWriteUtils.java#L406-L442","documentation":"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.","triggerScenarios":"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.","commonSituations":"Databases created via custom metastore scripts lacking the location URI; corrupted metastore rows; databases migrated between metastore backends losing the location property.","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"],"exampleFix":"// before\nCREATE TABLE ghostdb.t (i int); -- ghostdb has no location\n// after\nALTER DATABASE ghostdb SET LOCATION 'hdfs://nn/user/hive/warehouse/ghostdb.db';\nCREATE TABLE ghostdb.t (i int);","handlingStrategy":"validation","validationCode":"Database db = metastore.getDatabase(schema);\nif (db.getLocation() == null || db.getLocation().isEmpty()) {\n    throw new IllegalStateException(\"Database has no location: \" + schema);\n}","typeGuard":null,"tryCatchPattern":"try {\n    createTable(schema, ...);\n} catch (PrestoException e) {\n    if (e.getErrorCode() == HIVE_DATABASE_LOCATION_ERROR.toErrorCode()) {\n        // set the DB location or pass explicit LOCATION\n    } else throw e;\n}","preventionTips":["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"],"tags":["hive","metastore","database-location","ddl"],"backgroundTag":"missing-database-location","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"}