Re: [BUG] temporary file usage report with extended protocol and unnamed portals

Frédéric Yhuel <frederic.yhuel@dalibo.com>

From: Frédéric Yhuel <frederic.yhuel@dalibo.com>
To: Sami Imseih <samimseih@gmail.com>
Cc: Tom Lane <tgl@sss.pgh.pa.us>, PostgreSQL Hackers <pgsql-hackers@lists.postgresql.org>, Benoit Lobréau <benoit.lobreau@dalibo.com>, Guillaume Lelarge <guillaume.lelarge@dalibo.com>, Pierrick Chovelon <pierrick.chovelon@dalibo.com>
Date: 2025-08-21T12:02:40Z
Lists: pgsql-hackers

Attachments


On 4/26/25 20:57, Sami Imseih wrote:
> I found several issues with v4. It does not deal correctly with pipelining,
> and we should only really be concerned with dropping an unnamed
> portal only.
> 
> So, v5 now moves the DropPortal call after the unnamed portal was
> executed to completion ( as v4 was doing ), but does so only in the
> case in which we are not inside a transaction-control statement or
> the portal was executing a command that can be run inside a
> transaction block.

Having taken another look at this patch, I believe it is problematic as 
it does not align with the protocol documentation, which states:

"An unnamed portal is destroyed at the end of the transaction, or as 
soon as the next Bind statement specifying the unnamed portal as 
destination is issued."

Attached is another patch that strictly adheres to Tom's earlier 
proposal in this thread:

 > Perhaps a cleaner answer is to rearrange things in postgres.c
 > so that if there's a pre-existing unnamed portal, we drop that
 > before we ever set debug_query_string and friends at all.

This v6 patch includes the TAP test that I sent in my previous email, 
with some enhancements.

 From a user's point of view, Sami's patch is much better, because it 
always logs the right query (except for the SQL cursor), whereas this 
one doesn't log any queries in certain cases. However, it appears 
challenging to devise a clean solution that accomplishes our desired 
outcome.

Best regards,
Frédéric

Commits

  1. Drop unnamed portal immediately after execution to completion

  2. Override log_error_verbosity to "default" in test 009_log_temp_files

  3. Add tests for logging of temporary file removal and statement