diff --git a/gpMgmt/bin/gpcheckcat_modules/leaked_schema_dropper.py b/gpMgmt/bin/gpcheckcat_modules/leaked_schema_dropper.py index 1470064068f0424161a8582ece1fa4fcb21ed114..6cfe6233ec0b317224b5a17051b036561da5de37 100644 --- a/gpMgmt/bin/gpcheckcat_modules/leaked_schema_dropper.py +++ b/gpMgmt/bin/gpcheckcat_modules/leaked_schema_dropper.py @@ -13,6 +13,10 @@ class LeakedSchemaDropper: SELECT nspname, replace(nspname, 'pg_temp_','')::int as sess_id FROM gp_dist_random('pg_namespace') WHERE nspname ~ '^pg_temp_[0-9]+' + UNION ALL + SELECT nspname, replace(nspname, 'pg_toast_temp_','')::int as sess_id + FROM gp_dist_random('pg_namespace') + WHERE nspname ~ '^pg_toast_temp_[0-9]+' ) n LEFT OUTER JOIN pg_stat_activity x using (sess_id) WHERE x.sess_id is null UNION @@ -21,6 +25,10 @@ class LeakedSchemaDropper: SELECT nspname, replace(nspname, 'pg_temp_','')::int as sess_id FROM pg_namespace WHERE nspname ~ '^pg_temp_[0-9]+' + UNION ALL + SELECT nspname, replace(nspname, 'pg_toast_temp_','')::int as sess_id + FROM pg_namespace + WHERE nspname ~ '^pg_toast_temp_[0-9]+' ) n LEFT OUTER JOIN pg_stat_activity x using (sess_id) WHERE x.sess_id is null """ diff --git a/src/backend/commands/schemacmds.c b/src/backend/commands/schemacmds.c index 5fff196012cc7609eeec039386f7df6a966cc063..fdfae899c42568e459881450a1ebe6b1b945aac3 100644 --- a/src/backend/commands/schemacmds.c +++ b/src/backend/commands/schemacmds.c @@ -272,12 +272,16 @@ RemoveSchemas(DropStmt *drop) namespaceName); /* - * Additional check to protect reserved schema names, exclude temp - * schema + * Additional check to protect reserved schema names. + * + * But allow dropping temp schemas. This makes it much easier to get rid + * of leaked temp schemas. I wish it wasn't necessary, but we do tend to + * leak them on crashes, so let's make life a bit easier for admins. + * gpcheckcat will also try to automatically drop any leaked temp schemas. */ if (!allowSystemTableModsDDL && IsReservedName(namespaceName) && - (strlen(namespaceName) >= 7 && - strncmp(namespaceName, "pg_temp", 7) != 0)) + strncmp(namespaceName, "pg_temp_", 8) != 0 && + strncmp(namespaceName, "pg_toast_temp_", 14) != 0) ereport(ERROR, (errcode(ERRCODE_RESERVED_NAME), errmsg("cannot drop schema %s because it is required by the database system",