diff options
| author | Michael Paquier <michael@paquier.xyz> | 2025-11-05 14:35:16 +0900 |
|---|---|---|
| committer | Michael Paquier <michael@paquier.xyz> | 2025-11-05 14:35:16 +0900 |
| commit | 1fd981f05369340a8afa4d013a350b0b2ac6e33e (patch) | |
| tree | 762d242a953595194d39ab31d1987cbb00cf3bf6 /src/backend | |
| parent | 59dec6c0b09f717e4ce78d54f578d56ef93bcc53 (diff) | |
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.yhuel@dalibo.com>
Co-Authored-by: Sami Imseih <samimseih@gmail.com>
Co-Authored-by: Mircea Cadariu <cadariu.mircea@gmail.com>
Discussion: https://postgr.es/m/CAA5RZ0tTrTUoEr3kDXCuKsvqYGq8OOHiBwoD-dyJocq95uEOTQ%40mail.gmail.com
Diffstat (limited to 'src/backend')
| -rw-r--r-- | src/backend/tcop/postgres.c | 10 |
1 files changed, 10 insertions, 0 deletions
diff --git a/src/backend/tcop/postgres.c b/src/backend/tcop/postgres.c index 7dd75a490aa..2bd89102686 100644 --- a/src/backend/tcop/postgres.c +++ b/src/backend/tcop/postgres.c @@ -2327,6 +2327,16 @@ exec_execute_message(const char *portal_name, long max_rows) * message. The next protocol message will start a fresh timeout. */ disable_statement_timeout(); + + /* + * We completed fetching from an unnamed portal. There is no need + * for it beyond this point, so drop 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. + */ + if (portal->name[0] == '\0') + PortalDrop(portal, false); } /* Send appropriate CommandComplete to client */ |
