prestodb/presto · error · PrestoException

SCHEMA_NOT_EMPTY

SCHEMA_NOT_EMPTY

Error message

Schema not empty: 

What it means

dropSchema performs a sanity check before dropping the database in the metastore: if listTables or listViews report any objects in the schema, it throws SCHEMA_NOT_EMPTY. This is a safety guard so users get a clearer message than the metastore's own refusal to drop a non-empty database.

Source

Thrown at presto-hive/src/main/java/com/facebook/presto/hive/HiveMetadata.java:1030

        });

        Database database = Database.builder()
                .setDatabaseName(schemaName)
                .setLocation(location)
                .setOwnerType(USER)
                .setOwnerName(session.getUser())
                .build();

        metastore.createDatabase(getMetastoreContext(session), database);
    }

    @Override
    public void dropSchema(ConnectorSession session, String schemaName)
    {
        // basic sanity check to provide a better error message
        if (!listTables(session, schemaName).isEmpty() ||
                !listViews(session, schemaName).isEmpty()) {
            throw new PrestoException(SCHEMA_NOT_EMPTY, "Schema not empty: " + schemaName);
        }
        metastore.dropDatabase(getMetastoreContext(session), schemaName);
    }

    @Override
    public void renameSchema(ConnectorSession session, String source, String target)
    {
        metastore.renameDatabase(getMetastoreContext(session), source, target);
    }

    @Override
    public void createTable(ConnectorSession session, ConnectorTableMetadata tableMetadata, boolean ignoreExisting)
    {
        PrestoTableType tableType = isExternalTable(tableMetadata.getProperties()) ? EXTERNAL_TABLE : MANAGED_TABLE;
        Table table = prepareTable(session, tableMetadata, tableType);
        PrincipalPrivileges principalPrivileges = buildInitialPrivilegeSet(table.getOwner());
        HiveBasicStatistics basicStatistics = table.getPartitionColumns().isEmpty() ? createZeroStatistics() : createEmptyStatistics();

View on GitHub (pinned to 55bb57d202)

Solutions

  1. Drop all tables first: run SHOW TABLES and SHOW VIEWS in the schema and DROP each one
  2. Use DROP SCHEMA ... CASCADE (where supported) to drop the schema and its contents together
  3. Check for hidden/orphan tables in the metastore (hive metastore client or SHOW TABLES) and clean them
  4. If objects were already physically deleted, purge orphan metastore entries

Example fix

// before
DROP SCHEMA sales;
// after
DROP TABLE sales.orders;
DROP VIEW sales.daily;
DROP SCHEMA sales;
Defensive patterns

Strategy: try-catch

Validate before calling

// check emptiness before DROP SCHEMA
List<String> tables = metadata.listTables(session, schemaName);
List<String> views = metadata.listViews(session, schemaName);
if (!tables.isEmpty() || !views.isEmpty()) {
    throw new IllegalStateException("Schema not empty: " + tables.size() + " tables, " + views.size() + " views");
}

Try / catch

try {
    connector.dropSchema(session, schemaName);
} catch (PrestoException e) {
    if (e.getErrorCode().getCode() == StandardErrorCode.SCHEMA_NOT_EMPTY.code()) {
        // enumerate and drop tables/views, then retry once
    } else { throw e; }
}

Prevention

When it happens

Trigger: Calling DROP SCHEMA on a schema that still contains at least one table or view (including views created in other connectors that map into this schema, or tables visible via the metastore but filtered in the current UI).

Common situations: Forgetting to drop child tables/views first; orphaned metastore entries from a partially deleted dataset; views defined in another catalog pointing at the schema that listViews still counts.

Related errors


AI-assisted analysis of prestodb/presto@55bb57d202 (2026-09-04). Data as JSON: /api/errors/2b22100b4ac49b02. Report an issue: GitHub.