]> git.ipfire.org Git - thirdparty/postgresql.git/commitdiff
Make plpgsql_trap test more robust and less resource-intensive.
authorTom Lane <tgl@sss.pgh.pa.us>
Tue, 21 Apr 2026 14:54:39 +0000 (10:54 -0400)
committerTom Lane <tgl@sss.pgh.pa.us>
Tue, 21 Apr 2026 14:54:39 +0000 (10:54 -0400)
We were using "select count(*) into x from generate_series(1,
1_000_000_000_000)" to waste one second waiting for a statement
timeout trap.  Aside from consuming CPU to little purpose, this could
easily eat several hundred MB of temporary file space, which has been
observed to cause out-of-disk-space errors in the buildfarm.
Let's just use "pg_sleep(10)", which is far less resource-intensive.

Also update the "when others" exception handler so that if it does
ever again trap an error, it will tell us what error.  The cause of
these intermittent buildfarm failures had been obscure for awhile.

Discussion: https://postgr.es/m/557992.1776779694@sss.pgh.pa.us
Backpatch-through: 14

src/pl/plpgsql/src/expected/plpgsql_trap.out
src/pl/plpgsql/src/sql/plpgsql_trap.sql

index 62d1679c28f038eacaae1dc02b3b3116f58528e4..c37ac3b5c698379e435a5c1a2fc00ee7747cac99 100644 (file)
@@ -138,13 +138,11 @@ select * from foo;
 drop table foo;
 create function trap_timeout() returns void as $$
 begin
-  declare x int;
   begin
-    -- we assume this will take longer than 1 second:
-    select count(*) into x from generate_series(1, 1_000_000_000_000);
+    perform pg_sleep(10);
   exception
     when others then
-      raise notice 'caught others?';
+      raise notice 'caught others: %', sqlerrm;
     when query_canceled then
       raise notice 'nyeah nyeah, can''t stop me';
   end;
@@ -157,7 +155,7 @@ set statement_timeout to 1000;
 select trap_timeout();
 NOTICE:  nyeah nyeah, can't stop me
 ERROR:  end of function
-CONTEXT:  PL/pgSQL function trap_timeout() line 15 at RAISE
+CONTEXT:  PL/pgSQL function trap_timeout() line 13 at RAISE
 rollback;
 -- Test for pass-by-ref values being stored in proper context
 create function test_variable_storage() returns text as $$
index 5459b347e7f1f57a1a295121e88ad2d29aea2f8e..731d592040ed2c40c46cb40eadf2d4820a0d2381 100644 (file)
@@ -85,13 +85,11 @@ drop table foo;
 
 create function trap_timeout() returns void as $$
 begin
-  declare x int;
   begin
-    -- we assume this will take longer than 1 second:
-    select count(*) into x from generate_series(1, 1_000_000_000_000);
+    perform pg_sleep(10);
   exception
     when others then
-      raise notice 'caught others?';
+      raise notice 'caught others: %', sqlerrm;
     when query_canceled then
       raise notice 'nyeah nyeah, can''t stop me';
   end;