Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1ijwJW-0004ld-VY for pgsql-hackers@arkaria.postgresql.org; Wed, 25 Dec 2019 02:22:19 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1ijwJU-0006Oz-Hq for pgsql-hackers@arkaria.postgresql.org; Wed, 25 Dec 2019 02:22:16 +0000 Received: from makus.postgresql.org ([2001:4800:3e1:1::229]) by malur.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1ijwJU-0006Os-0y for pgsql-hackers@lists.postgresql.org; Wed, 25 Dec 2019 02:22:16 +0000 Received: from out5-smtp.messagingengine.com ([66.111.4.29]) by makus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1ijwJM-000194-VT for pgsql-hackers@lists.postgresql.org; Wed, 25 Dec 2019 02:22:14 +0000 Received: from compute4.internal (compute4.nyi.internal [10.202.2.44]) by mailout.nyi.internal (Postfix) with ESMTP id EF1F121448; Tue, 24 Dec 2019 21:22:07 -0500 (EST) Received: from mailfrontend2 ([10.202.2.163]) by compute4.internal (MEProxy); Tue, 24 Dec 2019 21:22:07 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=paquier.xyz; h= date:from:to:cc:subject:message-id:references:mime-version :content-type:in-reply-to; s=fm3; bh=MMJNKY8TK8zoaChAjkgcPR+AOXw KSNrnSD7ic2OGkq0=; b=ckg1190H8YomfZxTzVRpSRJJp6qRZueQTMIan2yIxEy 0pgQStq62Q7fvUBtBdgDDfSP4/JrJikk7EUkcOa1JTpgOAGrolYioZZB2/xZylts 5/l/I100wfr2Vo04loWubAzS4HNzOnq9CzZYcKkSnfhkNcBAJLf3De93mFaDxLjj 3mFDQD6s4dEu5e4QQqtPX+dPfqLHqHz1uMvuttscBzNfOW2BHJ5jo78j5dllRLKp 1xiThB9PbtFDf05eOn4SihPDSnS3hzlRF7xrXT6iuQzep9XvKxH+DvcLQb9HReAs mBbkkvcuClEawRkFMqi0eBTsqzc1v0SWyna3vf1P+Eg== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:content-type:date:from:in-reply-to :message-id:mime-version:references:subject:to:x-me-proxy :x-me-proxy:x-me-sender:x-me-sender:x-sasl-enc; s=fm1; bh=MMJNKY 8TK8zoaChAjkgcPR+AOXwKSNrnSD7ic2OGkq0=; b=bNpKwINcx0IbLlZ4LeQeES d1d+TpS2b41vlYuYnyJZOwPdeUeEpyB5C7lH/zzkmXO4mBC804vjfyNbPv+JRmzJ GOvS5KSH7zbk+ymBRlD9YAWn7cqClRlFv3ttNJUjmZDuMb0p2FA0jDI63oyzJzkQ 8FornqnyQM1phnKCF7czcY7fgaYQq2xHdRUyRWYh7fjtK+0yuYrg28G9S3aYdrA3 yfBOz0dRSuxH1CgApp2INqOFs/nJWTbQOJCoBuNI/0ltBq/77sQ6yvye9eSFqKaD 0OSWr//cKs59rv1mcRuYPYMtk6kGO6ZjuNZQgM8PpfNqEB8sqLrbdOjxAT5JEZaA == X-ME-Sender: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedufedrvddvvddgudehtdcutefuodetggdotefrod ftvfcurfhrohhfihhlvgemucfhrghsthforghilhdpqfgfvfdpuffrtefokffrpgfnqfgh necuuegrihhlohhuthemuceftddtnecusecvtfgvtghiphhivghnthhsucdlqddutddtmd enfghrlhcuvffnffculdejtddmnecujfgurhepfffhvffukfhfgggtuggjsehgtderredt tddvnecuhfhrohhmpefoihgthhgrvghlucfrrghquhhivghruceomhhitghhrggvlhesph grqhhuihgvrhdrgiihiieqnecukfhppeduuddurddutddvrddukedtrddukeehnecurfgr rhgrmhepmhgrihhlfhhrohhmpehmihgthhgrvghlsehprghquhhivghrrdighiiinecuve hluhhsthgvrhfuihiivgeptd X-ME-Proxy: Received: from paquier.xyz (ee0822lan1.rev.em-net.ne.jp [111.102.180.185]) by mail.messagingengine.com (Postfix) with ESMTPA id CB17A3060774; Tue, 24 Dec 2019 21:22:06 -0500 (EST) Date: Wed, 25 Dec 2019 11:22:03 +0900 From: Michael Paquier To: Mahendra Singh Cc: PostgreSQL Hackers Subject: 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 Message-ID: <20191225022203.GD3448@paquier.xyz> References: MIME-Version: 1.0 Content-Type: multipart/signed; micalg=pgp-sha512; protocol="application/pgp-signature"; boundary="zjcmjzIkjQU2rmur" Content-Disposition: inline In-Reply-To: List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk --zjcmjzIkjQU2rmur Content-Type: multipart/mixed; boundary="EY/WZ/HvNxOox07X" Content-Disposition: inline --EY/WZ/HvNxOox07X Content-Type: text/plain; charset=us-ascii Content-Disposition: inline Content-Transfer-Encoding: quoted-printable 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.)=20 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 --EY/WZ/HvNxOox07X Content-Type: text/x-diff; charset=us-ascii Content-Disposition: attachment; filename="drop-temp-schema-v1.patch" Content-Transfer-Encoding: quoted-printable diff --git a/src/backend/commands/dropcmds.c b/src/backend/commands/dropcmd= s.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."))); } =20 + /* + * 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 =3D=3D 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 =3D get_object_namespace(&address); if (!OidIsValid(namespaceId) || --EY/WZ/HvNxOox07X-- --zjcmjzIkjQU2rmur Content-Type: application/pgp-signature; name="signature.asc" -----BEGIN PGP SIGNATURE----- iQIzBAABCgAdFiEEG72nH6vTowiyblFKnvQgOdbyQH0FAl4Cx8sACgkQnvQgOdby QH0whg//bmRSyDepzF6vt/yZUv1nOmERtDRf7FYZp2giRmnJxiG40FOdMr+OQFul 1ZFXKaOJfsMlEbpapH90WWzGq1mFIkVF8gFdZtwQ8jIzA+SiliKoV8Xwg1q0eVrP b7ZXfTjfXDvcb8JcFGPe9HkPyJAR9i6yiS2UPNsGqWYfjE5U2wGOn6OiC5RDVqbl mntovuQKrXGS+tMpNFnfrrIY7cLhOZmkJCjDIKGlTdvCDK2l5Vn+dSdhxTE8MYWZ uLYVXmyT9XQpMH1roClNyzPqj2jfW6zgt9pp7VO/k4jdsnZ1HeYCWtcsLvq4DEj4 ED3e/Mi1pyHkweVdK7/6ol8cTFy4O1O3CPNq+r1hbZJScUAJZtol75vZedSWenny 9zGjvZ0FJE1TJgnASrKIJsj9fYmZv4+EdAgHem1VqV/Mc0RxmFVFT7yN2eMOXi2D UqFLN/tAsv3LwomusWGsTtUrCARXetQYfLXp3tWfnpFRj+W5gnxhL5+G7I8XC9z2 Rp3k3p+RPZMjPtt9J18TizZtcp9qZJzyih2spoSTvUwMejsaI99lDlRGc9rFD0uS D6MffxYWI8njxARTF3AbkpsED1/kRdunejaJ5dXvpW0EpNo/9ooyaIerxorkzprF nMXCMEwboaY1Fgg3SQDmsmjGLAuhhRDX9yXIRHVGLQcXSGzD7N8= =8p7o -----END PGP SIGNATURE----- --zjcmjzIkjQU2rmur--