pgsql: Drop unnamed portal immediately after execution to completion

From: Michael Paquier <michael(at)paquier(dot)xyz>
To: pgsql-committers(at)lists(dot)postgresql(dot)org
Subject: pgsql: Drop unnamed portal immediately after execution to completion
Date: 2025-11-05 05:43:31
Message-ID: E1vGWIt-0056al-2N@gemulon.postgresql.org
Views: Whole Thread | Raw Message | Download mbox | Resend email
Thread:
Lists: pgsql-committers pgsql-hackers

Drop unnamed portal immediately after execution to completion

Previously, unnamed portals were kept until the next Bind message or the
end of the transaction. This could cause temporary files to persist
longer than expected and make logging not reflect the actual SQL
responsible for the temporary file.

This patch changes exec_execute_message() to drop unnamed portals
immediately after execution to completion at the end of an Execute
message, making their removal more aggressive. This forces temporary
file cleanups to happen at the same time as the completion of the portal
execution, with statement logging correctly reflecting to which
statements these temporary files were attached to (see the diffs in the
TAP test updated by this commit for an idea).

The documentation is updated to describe the lifetime of unnamed
portals, and test cases are updated to verify temporary file removal and
proper statement logging after unnamed portal execution. This changes
how unnamed portals are handled in the protocol, hence no backpatch is
done.

Author: Frédéric Yhuel <frederic(dot)yhuel(at)dalibo(dot)com>
Co-Authored-by: Sami Imseih <samimseih(at)gmail(dot)com>
Co-Authored-by: Mircea Cadariu <cadariu(dot)mircea(at)gmail(dot)com>
Discussion: https://postgr.es/m/CAA5RZ0tTrTUoEr3kDXCuKsvqYGq8OOHiBwoD-dyJocq95uEOTQ%40mail.gmail.com

Branch
------
master

Details
-------
https://git.postgresql.org/pg/commitdiff/1fd981f05369340a8afa4d013a350b0b2ac6e33e

Modified Files
--------------
doc/src/sgml/protocol.sgml | 4 +--
src/backend/tcop/postgres.c | 10 +++++++
src/test/modules/test_misc/t/009_log_temp_files.pl | 33 +++++++++++-----------
3 files changed, 29 insertions(+), 18 deletions(-)

Responses

Browse pgsql-committers by date

  From Date Subject
Next Message Amit Kapila 2025-11-05 06:17:20 pgsql: Add sequence synchronization for logical replication.
Previous Message Richard Guo 2025-11-05 03:32:20 pgsql: Fix comments for ChangeVarNodes() and related functions

Browse pgsql-hackers by date

  From Date Subject
Next Message Michael Paquier 2025-11-05 05:44:39 Re: [BUG] temporary file usage report with extended protocol and unnamed portals
Previous Message David Rowley 2025-11-05 05:26:53 Re: Teaching planner to short-circuit empty UNION/EXCEPT/INTERSECT inputs