On Tue, Dec 24, 2019 at 04:50:58PM +0530, Mahendra Singh wrote: > We can fix this problem by either one way 1) reset myTempNamespace to > invalid while drooping schema of temp table 2) should not allow to drop > temporary table schema
(Please note that it is better not to cross-post on multiple lists, so I have removed pgsql-bugs from CC.) There is a little bit more to that, as we would basically need to do the work of RemoveTempRelationsCallback() once the temp schema is dropped, callback registered when the schema is correctly created at transaction commit (also we need to make sure that RemoveTempRelationsCallback is not called or unregistered if we were to authorize DROP SCHEMA on a temp schema). And then all the reset done at the beginning of AtEOXact_Namespace() would need to happen. Anyway, as dropping a temporary schema leads to an inconsistent behavior when recreating new temporary objects in a session that dropped it, that nobody has actually complained on the matter, and that in concept a temporary schema is linked to the session that created it, I think that we have a lot of arguments to just forbid the operation from happening. Please note as well that it is possible to drop temporary schemas of other sessions, still this is limited to owners of the schema. In short, let's tighten the logic, and we had better back-patch this one all the way down, 9.4 being broken. Attached is a patch to do that. The error message generated depends on the state of the session so I have not added a test for this reason, and the check is added before the ACL check. We could make the error message more generic, like "cannot drop temporary namespace". Any thoughts? -- Michael
diff --git a/src/backend/commands/dropcmds.c b/src/backend/commands/dropcmds.c index be7a40d5d2..13a7c327f3 100644 --- a/src/backend/commands/dropcmds.c +++ b/src/backend/commands/dropcmds.c @@ -101,6 +101,20 @@ RemoveObjects(DropStmt *stmt) errhint("Use DROP AGGREGATE to drop aggregate functions."))); } + /* + * Prevent drop of a temporary schema as this would mess up with + * the end-of-session callback cleaning up all temporary objects. + * As the in-memory state is not cleaned up either here, upon + * recreation of a temporary schema within the same session the + * temporary object handling would be inconsistent. + */ + if (stmt->removeType == OBJECT_SCHEMA && + isTempNamespace(address.objectId)) + ereport(ERROR, + (errcode(ERRCODE_WRONG_OBJECT_TYPE), + errmsg("cannot drop temporary namespace \"%s\"", + get_namespace_name(address.objectId)))); + /* Check permissions. */ namespaceId = get_object_namespace(&address); if (!OidIsValid(namespaceId) ||
signature.asc
Description: PGP signature