Add test for temporary file removal and WITH HOLD cursor
authorMichael Paquier <michael@paquier.xyz>
Sun, 16 Nov 2025 23:01:04 +0000 (08:01 +0900)
committerMichael Paquier <michael@paquier.xyz>
Sun, 16 Nov 2025 23:01:04 +0000 (08:01 +0900)
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 <cadariu.mircea@gmail.com>
Discussion: https://postgr.es/m/0a666d28-9080-4239-90d6-f6345bb43468@gmail.com

src/test/modules/test_misc/t/009_log_temp_files.pl

index 462a949e41141507834c4b4a9c1c979856dd7c88..697e02401158357f7fbb2544d0446d13104c6920 100644 (file)
@@ -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;