pgsql: Say what WAIT's snapshot restriction actually is

From: Alexander Korotkov <akorotkov(at)postgresql(dot)org>
To: pgsql-committers(at)lists(dot)postgresql(dot)org
Subject: pgsql: Say what WAIT's snapshot restriction actually is
Date: 2026-09-18 06:39:01
Message-ID: E1x7SFR-00000000E01-3cbs@gemulon.postgresql.org
Views: Whole Thread | Raw Message | Download mbox | Resend email
Thread:
Lists: pgsql-committers

Say what WAIT's snapshot restriction actually is

The reference page said WAIT "cannot be used in contexts where such a
snapshot must remain active, including transactions running at isolation
levels higher than READ COMMITTED", which reads as a blanket ban at those
levels. It is not one. The rule the code enforces is that the current
transaction must hold no snapshot, and a transaction-snapshot-mode
transaction has no snapshot until its first query: WaitStmt is exempt in
PlannedStmtRequiresSnapshot(), so the command itself does not take one.
WAIT therefore works before that first query, which is the order an
application wants anyway, and it is what 447aae13b03 set out to allow by
keeping the wait snapshot-free.

State the rule in terms of the snapshot rather than the isolation level,
say that WAIT acquires none of its own and name the other ways to hold
one, and give the consequence of holding one: it can delay replay, which
standby_replay waits for and which the other standby modes ultimately
depend on as well.

The error for a held snapshot named the internal snapshot states instead
of saying what the user did, and attached the isolation-level
explanation as DETAIL unconditionally, so a READ COMMITTED session with a
cursor was told its isolation level was too high. Report what is held
rather than how it is held, and emit the DETAIL only when the isolation
level is in fact the reason.

Reported-by: Sami Imseih <samimseih(dot)pg(at)gmail(dot)com>
Reported-by: Xuneng Zhou <xunengzhou(at)gmail(dot)com>
Reviewed-by: Sami Imseih <samimseih(dot)pg(at)gmail(dot)com>
Reviewed-by: Xuneng Zhou <xunengzhou(at)gmail(dot)com>
Discussion: https://postgr.es/m/CAN12%2BYJddgAZzA36JZFX%2BYrnNR7Uubp9qWFz6ASs3v0kL30AMA%40mail.gmail.com
Backpatch-through: 19

Branch
------
master

Details
-------
https://git.postgresql.org/pg/commitdiff/26a3c0a45cc6017ee7f334c0ef63292d5e101b58

Modified Files
--------------
doc/src/sgml/ref/wait.sgml | 14 ++++++++++----
src/backend/commands/wait.c | 6 ++++--
src/test/recovery/t/049_wait_for_lsn.pl | 27 ++++++++++++++++++++++++++-
3 files changed, 40 insertions(+), 7 deletions(-)

Browse pgsql-committers by date

  From Date Subject
Next Message Alexander Korotkov 2026-09-18 06:39:03 pgsql: Say what WAIT's snapshot restriction actually is
Previous Message Amit Kapila 2026-09-18 05:34:19 pgsql: Don't quote the relation name twice in EXCEPT clause errors.