prestodb/presto · error · PrestoException
SCHEMA_NOT_EMPTY
SCHEMA_NOT_EMPTY
Error message
Schema not empty:
What it means
MemoryMetadata.dropSchema refuses to drop a schema that still contains tables. After confirming the schema exists, it scans the tables map for any table whose schemaName matches; if found, it throws PrestoException SCHEMA_NOT_EMPTY. The schema must be emptied (all tables dropped) before it can be removed.
Source
Thrown at presto-memory/src/main/java/com/facebook/presto/plugin/memory/MemoryMetadata.java:129
{
if (schemas.contains(schemaName)) {
throw new PrestoException(ALREADY_EXISTS, format("Schema [%s] already exists", schemaName));
}
schemas.add(schemaName);
}
@Override
public synchronized void dropSchema(ConnectorSession session, String schemaName)
{
if (!schemas.contains(schemaName)) {
throw new PrestoException(NOT_FOUND, format("Schema [%s] does not exist", schemaName));
}
boolean tablesExist = tables.values().stream()
.anyMatch(table -> table.getSchemaName().equals(schemaName));
if (tablesExist) {
throw new PrestoException(SCHEMA_NOT_EMPTY, "Schema not empty: " + schemaName);
}
verify(schemas.remove(schemaName));
}
@Override
public synchronized ConnectorTableHandle getTableHandle(ConnectorSession session, SchemaTableName schemaTableName)
{
Long tableId = tableIds.get(schemaTableName);
if (tableId == null) {
return null;
}
return tables.get(tableId);
}
@Override
public synchronized ConnectorTableMetadata getTableMetadata(ConnectorSession session, ConnectorTableHandle tableHandle)
{View on GitHub (pinned to 55bb57d202)
Solutions
- Drop all tables first: for each table run DROP TABLE memory.<schema>.<table>
- Use DROP SCHEMA ... CASCADE if the SQL layer in your version supports it for this connector
- Query system metadata (memory.information_schema.tables) to enumerate tables to drop
- Reorder teardown scripts to drop tables before schemas
Example fix
// before DROP SCHEMA memory.test_schema; -- SCHEMA_NOT_EMPTY // after DROP TABLE memory.test_schema.t1; DROP TABLE memory.test_schema.t2; DROP SCHEMA memory.test_schema;
Defensive patterns
Strategy: validation
Validate before calling
// Drop all tables in the schema before dropping the schema
List<String> tables = metadata.listTables(session, new SchemaTableName("memory", schemaName))
.stream().map(t -> t.getTableName()).collect(toList());
for (String table : tables) {
metadata.dropTable(session, new SchemaTableName(schemaName, table));
}
metadata.dropSchema(session, schemaName); Try / catch
try {
metadata.dropSchema(session, schemaName);
} catch (PrestoException e) {
if (SCHEMA_NOT_EMPTY.equals(e.getErrorCode())) {
dropAllTablesThenRetry(schemaName);
} else throw e;
} Prevention
- Always drop child tables before schemas in teardown scripts
- Enumerate tables via information_schema/system metadata first
- Fail-safe cleanup: loop until schema lists zero tables
- Avoid creating tables you never clean up in shared memory catalogs
When it happens
Trigger: DROP SCHEMA memory.<name> while tables created via CREATE TABLE memory.<name>.<t> still exist in that schema.
Common situations: Trying to tear down test schemas without dropping tables first; teardown scripts that skip table cleanup on failure; forgetting that memory connector has no CASCADE in this code path.
Related errors
AI-assisted analysis of prestodb/presto@55bb57d202 (2026-09-04).
Data as JSON: /api/errors/70ce4ee9e33c07fe.
Report an issue: GitHub.