Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.96) (envelope-from ) id 1vJQof-006DXx-0L for pgsql-hackers@arkaria.postgresql.org; Thu, 13 Nov 2025 06:28:20 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.96) (envelope-from ) id 1vJQoc-00GjIv-2p for pgsql-hackers@arkaria.postgresql.org; Thu, 13 Nov 2025 06:28:18 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.96) (envelope-from ) id 1vJQob-00GjIn-31 for pgsql-hackers@lists.postgresql.org; Thu, 13 Nov 2025 06:28:18 +0000 Received: from fout-a3-smtp.messagingengine.com ([103.168.172.146]) by magus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.96) (envelope-from ) id 1vJQoZ-007UC7-0D for pgsql-hackers@lists.postgresql.org; Thu, 13 Nov 2025 06:28:17 +0000 Received: from phl-compute-12.internal (phl-compute-12.internal [10.202.2.52]) by mailfout.phl.internal (Postfix) with ESMTP id C0D27EC008E; Thu, 13 Nov 2025 01:28:12 -0500 (EST) Received: from phl-mailfrontend-01 ([10.202.2.162]) by phl-compute-12.internal (MEProxy); Thu, 13 Nov 2025 01:28:12 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=paquier.xyz; h= cc:cc:content-type:content-type:date:date:from:from:in-reply-to :in-reply-to:message-id:mime-version:references:reply-to:subject :subject:to:to; s=fm3; t=1763015292; x=1763101692; bh=EppPMK3A9x b2B57AYdapEFdf3F2JcvHIzODn8KIxbZ4=; b=iyG6uF0WTDrfpC1Gm9URSA7oeO 20M3XZdTHunF3lKbx2lwibrMkdSEN+Dl1Pp1ljLvBe328HpQZoZ6JpgWukxkwQS1 6/Ib7W4lTNh0WE0lGo9VfRTkcGDCBa4mUGTSxQN7uW2jMa3cAtCaSXPy+i0bQk0U 8bJRns3A+fAZz+Cbt1DQFOIiD0C1aIBU7hYbvteMEmr/a9EB+yT2SCzM6DW0bxhI O9cHs3E9lRTtomArulQ2wOXD2raeuDtRO8c6pjOyBpeMUdKHH2i6GNQh7lvKJQDT x30a9/gBPmAoCMmNnl7j5Q5cjHhClaLfBgJR8SqOsGQRi54BjVVH68ZMDeqw== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:cc:content-type:content-type:date:date :feedback-id:feedback-id:from:from:in-reply-to:in-reply-to :message-id:mime-version:references:reply-to:subject:subject:to :to:x-me-proxy:x-me-sender:x-me-sender:x-sasl-enc; s=fm3; t= 1763015292; x=1763101692; bh=EppPMK3A9xb2B57AYdapEFdf3F2JcvHIzOD n8KIxbZ4=; b=hhawZdinRdWeF0g/uze0Hhn5cJAc7JDKUn3WonlfyyU6NHioigE aGbQsTKrf2ND4y+UPj8q9sbWXgzhMamzRaD1kO9ti73Uj/08OlzHjEzOCQagXJ7Z r+i1q89NJNiSYL+lXvHGLjUWjbEckM+AkfcUMtrWRxpVVK9+jrhjMHN+gytjHYKo y3+RigZJ+pQ1D2gP24loJ/U7bMesq3hWht+4xKZyeaHGALforEQrsYO+eeShnIT7 FfWlCrrxcKHh+PfWgCs7KJVo5uZJ7L9PGREZ8idnCuBh1fsMa8LPu21G5+qB74v+ rHvmHwKA0PeSEaQQNW3awougBDScdoaLKNg== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeeffedrtdeggddvtdeivdefucetufdoteggodetrf dotffvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdfurfetoffkrfgpnffqhgenuceu rghilhhouhhtmecufedttdenucesvcftvggtihhpihgvnhhtshculddquddttddmnegfrh hlucfvnfffucdljedtmdenucfjughrpeffhffvvefukfhfgggtuggjsehgtderredttdej necuhfhrohhmpefoihgthhgrvghlucfrrghquhhivghruceomhhitghhrggvlhesphgrqh huihgvrhdrgiihiieqnecuggftrfgrthhtvghrnhepveetjefgjeevgedukeehieeuieeu ieevueeiudegheevuefggfduueelgeelieetnecuvehluhhsthgvrhfuihiivgeptdenuc frrghrrghmpehmrghilhhfrhhomhepmhhitghhrggvlhesphgrqhhuihgvrhdrgiihiidp nhgspghrtghpthhtohephedpmhhouggvpehsmhhtphhouhhtpdhrtghpthhtoheptggrug grrhhiuhdrmhhirhgtvggrsehgmhgrihhlrdgtohhmpdhrtghpthhtoheprhhosggvrhht mhhhrggrshesghhmrghilhdrtghomhdprhgtphhtthhopehtghhlsehsshhsrdhpghhhrd hprgdruhhspdhrtghpthhtohepfhhrvgguvghrihgtrdihhhhuvghlsegurghlihgsohdr tghomhdprhgtphhtthhopehpghhsqhhlqdhhrggtkhgvrhhssehlihhsthhsrdhpohhsth hgrhgvshhqlhdrohhrgh X-ME-Proxy: Feedback-ID: i0fe9450f:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Thu, 13 Nov 2025 01:27:48 -0500 (EST) Date: Thu, 13 Nov 2025 15:27:23 +0900 From: Michael Paquier To: Mircea Cadariu Cc: Robert Haas , Tom Lane , =?iso-8859-1?Q?Fr=E9d=E9ric?= Yhuel , PostgreSQL Hackers Subject: Re: pgsql: Drop unnamed portal immediately after execution to completion Message-ID: References: <1982325.1762810082@sss.pgh.pa.us> <00d71a54-2118-4b18-87e8-33f4a99dc624@gmail.com> MIME-Version: 1.0 Content-Type: multipart/signed; micalg=pgp-sha512; protocol="application/pgp-signature"; boundary="VRlUH6Ha4FDi4uJe" Content-Disposition: inline In-Reply-To: <00d71a54-2118-4b18-87e8-33f4a99dc624@gmail.com> List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk --VRlUH6Ha4FDi4uJe Content-Type: multipart/mixed; boundary="ymSkWWb2wMYYhose" Content-Disposition: inline --ymSkWWb2wMYYhose Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: quoted-printable On Wed, Nov 12, 2025 at 11:14:26AM +0000, Mircea Cadariu wrote: > I understand the point that=E2=80=99s been raised. Would it be an option = to indeed > revert the portal drop in postgres.c, but then append the right query in = the > "temporary file: ..." log line instead? This would work at least for me. This is new, attaching the information to a Vfd in fd.c. Not sure that adding this information to this structure is a good concept. This layer of the code has no idea of query strings currently, so that feels a bit like a layer violation. Thinking a bit outside the box.. I was wondering about a plan D (plan A is what's on HEAD, plan B is copying around the query string, plan C this Vfd approach) where we shut down the executor when we have finished the execution of an unnamed portal, with something like the attached based on a more aggressive PortalCleanup(). However, that would not fly far if the client decides to send an extra execute message post-portal-completion where we'd still want the executor to be around, even if there are no rows to process. We presumably do not need the temp files anymore at this stage, but I don't really like the fact that we'd need to somehow take a shortcut if we want only to clean up the temp files. Perhaps the best answer for now is to revert and continue the discussion for this cycle as there seem to be little love for the current HEAD's solution with the protocol change. If folks have more ideas or input, please feel free. -- Michael --ymSkWWb2wMYYhose Content-Type: text/x-diff; charset=us-ascii Content-Disposition: attachment; filename="portal-cleanup.patch" Content-Transfer-Encoding: quoted-printable diff --git a/src/backend/tcop/postgres.c b/src/backend/tcop/postgres.c index 2bd89102686e..8d3739298afe 100644 --- a/src/backend/tcop/postgres.c +++ b/src/backend/tcop/postgres.c @@ -38,6 +38,7 @@ #include "commands/async.h" #include "commands/event_trigger.h" #include "commands/explain_state.h" +#include "commands/portalcmds.h" #include "commands/prepare.h" #include "common/pg_prng.h" #include "jit/jit.h" @@ -2330,13 +2331,14 @@ exec_execute_message(const char *portal_name, long = max_rows) =20 /* * We completed fetching from an unnamed portal. There is no need - * for it beyond this point, so drop it now rather than wait for + * for it beyond this point, so clean it now rather than wait for * the next Bind message to do this cleanup. This ensures that * the correct statement is logged when cleaning up temporary file - * usage. + * usage with the executor shutdown. */ - if (portal->name[0] =3D=3D '\0') - PortalDrop(portal, false); + if (portal->name[0] =3D=3D '\0' && + portal->cleanup) + PortalCleanup(portal); } =20 /* Send appropriate CommandComplete to client */ --ymSkWWb2wMYYhose-- --VRlUH6Ha4FDi4uJe Content-Type: application/pgp-signature; name="signature.asc" -----BEGIN PGP SIGNATURE----- iQIzBAABCgAdFiEEG72nH6vTowiyblFKnvQgOdbyQH0FAmkVeksACgkQnvQgOdby QH3nwQ//cWaV1jXDpDhwrIUkYeoPedEqz+cPC0mw26FgcGxSp/dreqBzZiow2+27 NFg5vWOzD6Ra2F9DKsTcbuUyjcGvBvE/QR0whgSUfw4TzkwFVXaMRHkqsNM3m5fl TgmBoA3RezZyp7yERmrOmtyQGIN03alKLlrFLNhWOyCEntMskC52OSAIfjylK3zt zrxUZzcupDNJcwT7ST+V9Pd9FdogXq9/mH0mn/JOAEu5awI84j8XGFPJ1jbFhbbL puzsgxKCOuAWDx604fnbdupaiFi82OXPsZ/kmoxKaOhKE5pWDE/JVyUY/hiBzmYn iPElxLz7z2eYpTbuHjpXguA0liv5e+XYx2Gx3I+qBWvORYY5YY6l2OtY6nwxuCUf yzY1RV7Vg6nCIExcdvWaHsXg6Whvf2XsGA3HDG3V28VLtqabBZSSIvTf0L4GpPZt 19GEWpoXACfxjPUhqCeX/ofc+PeIodZixDXykhbzKYKwfKNbDkwDea7fLtqhMsWi Q4+tzhaokL++TsfgWlRsZXZJfp6mkShdUfS4OeowXtfWQ5sC6h/p9gqUJjeFiI+G AmJ0c9813AzPQ6Yt7IJ/XN0rgnkqMmdy7v/whVitN/jkKxx31pQH9ZUmbndNT4FU sWA8p5XEOyjcdDMe20HL7YyO0q9nJxsn2lfWwzRRFWVr88a0uQ0= =3a7w -----END PGP SIGNATURE----- --VRlUH6Ha4FDi4uJe--