From e7cde9dad285acb579b189e82a57fa7b98f23a11 Mon Sep 17 00:00:00 2001 From: Michael Paquier Date: Mon, 17 Nov 2025 08:01:04 +0900 Subject: [PATCH] Add test for temporary file removal and WITH HOLD cursor This new test, added in 009_log_temp_files, checks that the temporary files created by a WITH HOLD cursor are dropped at the end of the transaction where the transaction has been created. The portal's executor is shutdown in PersistHoldablePortal(), after for example some forced detoast, so as the cursor data can be accessed without requiring a snapshot. Author: Mircea Cadariu Discussion: https://postgr.es/m/0a666d28-9080-4239-90d6-f6345bb43468@gmail.com --- .../modules/test_misc/t/009_log_temp_files.pl | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/src/test/modules/test_misc/t/009_log_temp_files.pl b/src/test/modules/test_misc/t/009_log_temp_files.pl index 462a949e411..697e0240115 100644 --- a/src/test/modules/test_misc/t/009_log_temp_files.pl +++ b/src/test/modules/test_misc/t/009_log_temp_files.pl @@ -123,12 +123,27 @@ ok( $node->log_contains( $log_offset), "cursor"); +note "cursor WITH HOLD: temporary file dropped under COMMIT"; +$log_offset = -s $node->logfile; +$node->safe_psql( + "postgres", qq{ +BEGIN; +DECLARE holdcur CURSOR WITH HOLD FOR SELECT a FROM foo ORDER BY a OFFSET 4996; +FETCH 10 FROM holdcur; +COMMIT; +CLOSE holdcur; +}); +ok( $node->log_contains( + qr/LOG:\s+temporary file: path.*\n.*\ STATEMENT:\s+COMMIT;/s, + $log_offset), + "cursor WITH HOLD"); + note "prepare/execute: temporary file dropped under EXECUTE"; $log_offset = -s $node->logfile; $node->safe_psql( "postgres", qq{ BEGIN; -PREPARE p1 AS SELECT a FROM foo ORDER BY a OFFSET 4996; +PREPARE p1 AS SELECT a FROM foo ORDER BY a OFFSET 4997; EXECUTE p1; DEALLOCATE p1; END;