pgsql: Explicitly forbid non-top-level WAIT FOR execution

From: Alexander Korotkov <akorotkov(at)postgresql(dot)org>
To: pgsql-committers(at)lists(dot)postgresql(dot)org
Subject: pgsql: Explicitly forbid non-top-level WAIT FOR execution
Date: 2026-04-13 11:05:33
Message-ID: E1wCF6i-000mOw-1a@gemulon.postgresql.org
Views: Whole Thread | Raw Message | Download mbox | Resend email
Thread:
Lists: pgsql-committers

Explicitly forbid non-top-level WAIT FOR execution

Previously we were relying on a snapshot-based check to detect invalid
execution contexts. However, when WAIT FOR is wrapped into a stored
procedure or a DO block, it could pass this check, causing an error
elsewhere.

This commit implements an explicit isTopLevel check to reject WAIT FOR
when called from within a function, procedure, or DO block. The
isTopLevel check catches these cases early with a clear error message,
matching the pattern used by other utility commands like VACUUM and
REINDEX. The snapshot check is retained for the remaining case:
top-level execution within a transaction block using an isolation level
higher than READ COMMITTED.

Also adds tests for WAIT FOR LSN wrapped in a procedure and DO block,
complementing the existing test that uses a function wrapper. Relevant
documentation paragraph is also added.

Reported-by: Satyanarayana Narlapuram <satyanarlapuram(at)gmail(dot)com>
Discussion: https://postgr.es/m/CAHg%2BQDcN-n3NUqgRtj%3DBQb9fFQmH8-DeEROCr%3DPDbw_BBRKOYA%40mail.gmail.com
Author: Satyanarayana Narlapuram <satyanarlapuram(at)gmail(dot)com>
Reviewed-by: Alexander Korotkov <aekorotkov(at)gmail(dot)com>
Reviewed-by: Xuneng Zhou <xunengzhou(at)gmail(dot)com>

Branch
------
master

Details
-------
https://git.postgresql.org/pg/commitdiff/a8b61c23c5ff980312026a05cab5502aa31fd710

Modified Files
--------------
doc/src/sgml/ref/wait_for.sgml | 8 ++++++++
src/backend/commands/wait.c | 23 +++++++++++++++++------
src/backend/tcop/utility.c | 3 ++-
src/include/commands/wait.h | 3 ++-
src/test/recovery/t/049_wait_for_lsn.pl | 30 +++++++++++++++++++++++++++---
5 files changed, 56 insertions(+), 11 deletions(-)

Browse pgsql-committers by date

  From Date Subject
Next Message Robert Haas 2026-04-13 12:46:53 pgsql: pg_plan_advice: Handle non-repeatable TABLESAMPLE scans.
Previous Message Peter Eisentraut 2026-04-13 09:18:56 pgsql: Update Unicode data to CLDR 48.2