Re: Assert failure due to "drop schema pg_temp_3 cascade" for temporary tables and \d+ is not showing any info after drooping temp table schema

Michael Paquier <[email protected]>
Newsgroups gmane.comp.db.postgresql.devel.general
Message-ID <[email protected]>
On Tue, Jan 07, 2020 at 01:06:08PM -0500, Tom Lane wrote:
> I still agree with Robert that a052f6c is a bad idea.  It's not the case
> that that's blocking "any connected user" from causing an issue.  The
> temp schemas are always owned by the bootstrap superuser, so only a
> superuser could delete them.  All that that patch is doing is preventing
> superusers from doing something that they could reasonably wish to do,
> and that is perfectly safe when there's not concurrent usage of the
> schema.  We are not normally that nanny-ish, and the case for being so
> here seems pretty thin.

Okay, I am running out of arguments then, so attached is a patch to
address things.  I would also prefer if we keep the relation name in
the log even if the namespace is missing.
--
Michael
drop-temp-schema-adjust-v2.patch (text/x-diff, 2.2 KB)
diff --git a/src/backend/commands/dropcmds.c b/src/backend/commands/dropcmds.c
index e7891a4418..b3131ab208 100644
--- a/src/backend/commands/dropcmds.c
+++ b/src/backend/commands/dropcmds.c
@@ -101,21 +101,6 @@ 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) ||
diff --git a/src/backend/postmaster/autovacuum.c b/src/backend/postmaster/autovacuum.c
index f0e40e36af..f6afe4dbb8 100644
--- a/src/backend/postmaster/autovacuum.c
+++ b/src/backend/postmaster/autovacuum.c
@@ -2250,11 +2250,22 @@ do_autovacuum(void)
 		}
 
 		/* OK, let's delete it */
-		ereport(LOG,
-				(errmsg("autovacuum: dropping orphan temp table \"%s.%s.%s\"",
-						get_database_name(MyDatabaseId),
-						get_namespace_name(classForm->relnamespace),
-						NameStr(classForm->relname))));
+		if (log_min_messages <= LOG)
+		{
+			char       *nspname = get_namespace_name(classForm->relnamespace);
+
+			if (nspname != NULL)
+				ereport(LOG,
+						(errmsg("autovacuum: dropping orphan temp table \"%s.%s.%s\"",
+								get_database_name(MyDatabaseId),
+								get_namespace_name(classForm->relnamespace),
+								NameStr(classForm->relname))));
+			else
+				ereport(LOG,
+						(errmsg("autovacuum: dropping orphan temp table \"%s.(null).%s\" with OID %u",
+								get_database_name(MyDatabaseId),
+								NameStr(classForm->relname), relid)));
+		}
 
 		object.classId = RelationRelationId;
 		object.objectId = relid;
signature.asc (application/pgp-signature, 833 B)
-----BEGIN PGP SIGNATURE-----

iQIzBAABCgAdFiEEG72nH6vTowiyblFKnvQgOdbyQH0FAl4VJdkACgkQnvQgOdby
QH3hDxAAjnfaB8jW6F3jvP9Sgx76k5HpaKaCrRx9dRmelLpo813VBTF4CEbaFaVa
b4QXsvqlSCqrDyjhW4UIYaIbOJOwztIojPKPU6rH7BduVetN/yq+QBoVLWsmEzko
WHfa8Krq+X9s/jltJDHvXk9ApDNcW2mSbPRtCgkwFZ4hgrqGHoDIEi5Db1JzbKOR
uu8cxDzUHIDoIe84+yGpjgg2nNKScDUVNTE8jDCgr+JHnrVwHycO4rvDcMOw2ohY
+V1rNtRFRCD/asSdiK5g6cI39tWjWx5rcA6/FbsE4jRGedtukOisZaO8C9bnM+xS
be4jfVBOlLeAcF1utiOEZbcHFAxbzVmvca5OylMZKurC+53JoG3bAxhdqj3EkKs3
qop/9VQ0LbMOfw4wuREDqGFOpg1pPSv0haC3Bh1XPFVOiU3uVuOhbtp8agyaaZFy
16m2ozbg2VF29EUWue9ldSXGgaiw3LY+XB/vYtMiCr5E6m8jFlBNzICkVTAAZ431
PKI6IjOtXJDFTCbt5zoL10HLmmhwNRj1BCx0yn1Pzxd9pp/wYwNfyL1xtxh87Gz/
/lZl3etPVpxuXjUu2J1MSUy5p6JmEA/lvPC3xV8QlFUMo0ClU073u1I8g6MP0Fpv
bo+f7WxGxatyFJL4I3QbtuyACQdU4Xc4RLXPp+vnDjdbCaXOYkM=
=dKJp
-----END PGP SIGNATURE-----
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.