Skip to content

Commit f195835

Browse files
committed
Forbid DROP SCHEMA on temporary namespaces
This operation was possible for the owner of the schema or a superuser. Down to 9.4, doing this operation would cause inconsistencies in a session whose temporary schema was dropped, particularly if trying to create new temporary objects after the drop. A more annoying consequence is a crash of autovacuum on an assertion failure when logging information about an orphaned temp table dropped. Note that because of 246a6c8 (present in v11~), which has made the removal of orphaned temporary tables more aggressive, the failure could be triggered more easily, but it is possible to reproduce down to 9.4. Reported-by: Mahendra Singh, Prabhat Sahu Author: Michael Paquier Reviewed-by: Kyotaro Horiguchi, Mahendra Singh Discussion: https://postgr.es/m/CAKYtNAr9Zq=1-ww4etHo-VCC-k120YxZy5OS01VkaLPaDbv2tg@mail.gmail.com Backpatch-through: 9.4
1 parent 8e89bc6 commit f195835

File tree

1 file changed

+16
-0
lines changed

1 file changed

+16
-0
lines changed

src/backend/commands/dropcmds.c

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
#include "nodes/makefuncs.h"
2828
#include "parser/parse_type.h"
2929
#include "utils/builtins.h"
30+
#include "utils/lsyscache.h"
3031
#include "utils/syscache.h"
3132

3233

@@ -109,6 +110,21 @@ RemoveObjects(DropStmt *stmt)
109110
ReleaseSysCache(tup);
110111
}
111112

113+
/*
114+
* Prevent the drop of a temporary schema, be it owned by the current
115+
* session or another backend as this would mess up with the callback
116+
* registered to clean up temporary objects at the end of a session.
117+
* Note also that the creation of any follow-up temporary object would
118+
* result in inconsistencies within the session whose temporary schema
119+
* has been dropped.
120+
*/
121+
if (stmt->removeType == OBJECT_SCHEMA &&
122+
isAnyTempNamespace(address.objectId))
123+
ereport(ERROR,
124+
(errcode(ERRCODE_WRONG_OBJECT_TYPE),
125+
errmsg("cannot drop temporary schema \"%s\"",
126+
get_namespace_name(address.objectId))));
127+
112128
/* Check permissions. */
113129
namespaceId = get_object_namespace(&address);
114130
if (!OidIsValid(namespaceId) ||

0 commit comments

Comments
 (0)