postgres.git / summary / log / commit / refs
commit 786540085dbd5bccb5d8bfb9b519c4ffbf07ec28
Author: Michael Paquier <michael@paquier.xyz>
Date: Fri Dec 27 08:59:16 2019 +0000
First released in: master (reverted before release), REL9_4_STABLE (reverted before release), REL9_5_STABLE (reverted before release), REL9_6_STABLE (reverted before release), REL_10_STABLE (reverted before release), REL_11_STABLE (reverted before release), REL_12_STABLE (reverted before release)
Reverted by: b83ba2e6e706 (in 9.4.26), 86949c2f1207 (in 9.5.21), 50174b70e779 (in 9.6.17), 0c046f816902 (in 10.12), 789bc293b341 (in 11.7), a1c003e5ff82 (in 12.2), 65192e02441c (in 13.0)
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
src/backend/commands/dropcmds.c | 15 +++++++++++++++
1 file changed, 15 insertions(+)
diff --git a/src/backend/commands/dropcmds.c b/src/backend/commands/dropcmds.c
index f6d665239b9..d9c30013493 100644
--- a/src/backend/commands/dropcmds.c
+++ b/src/backend/commands/dropcmds.c
@@ -101,6 +101,21 @@ RemoveObjects(DropStmt *stmt)
errhint("Use DROP AGGREGATE to drop aggregate functions.")));
}
+ /*
+ * Prevent the drop of a temporary schema, be it owned by the current
+ * session or another backend as this would mess up with the callback
+ * registered to clean up temporary objects at the end of a session.
+ * Note also that the creation of any follow-up temporary object would
+ * result in inconsistencies within the session whose temporary schema
+ * has been dropped.
+ */
+ if (stmt->removeType == OBJECT_SCHEMA &&
+ isAnyTempNamespace(address.objectId))
+ ereport(ERROR,
+ (errcode(ERRCODE_WRONG_OBJECT_TYPE),
+ errmsg("cannot drop temporary schema \"%s\"",
+ get_namespace_name(address.objectId))));
+
/* Check permissions. */
namespaceId = get_object_namespace(&address);
if (!OidIsValid(namespaceId) ||
[parent: ee206cb830ef]