Reject WAIT FOR earlier in transaction-snapshot mode

From: Sami Imseih <samimseih(dot)pg(at)gmail(dot)com>
To: Postgres hackers <pgsql-hackers(at)lists(dot)postgresql(dot)org>
Subject: Reject WAIT FOR earlier in transaction-snapshot mode
Date: 2026-09-08 19:55:14
Message-ID: CAN12+YJddgAZzA36JZFX+YrnNR7Uubp9qWFz6ASs3v0kL30AMA@mail.gmail.com
Views: Whole Thread | Raw Message | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

Hi,

The WAIT FOR docs state:

"WAIT FOR must be executed as a top-level command. It cannot be
executed from a function, procedure, or DO block. It also requires
that no active or registered snapshot be held, and therefore cannot be
used in contexts where such a snapshot must remain active, including
transactions running at isolation levels higher than READ COMMITTED."

So this reads as any transaction above READ COMMITTED should reject WAIT FOR.
However, in REPEATABLE READ and SERIALIZABLE, you are allowed to call
WAIT FOR before taking the snapshot.

```
postgres=# BEGIN ISOLATION LEVEL REPEATABLE READ;
BEGIN
postgres=*# WAIT FOR LSN '0/0' WITH (MODE 'primary_flush');
status
---------
success
(1 row)

postgres=*# select 1;
?column?
----------
1
(1 row)

postgres=*# WAIT FOR LSN '0/0' WITH (MODE 'primary_flush');
ERROR: WAIT FOR must be called without an active or registered snapshot
DETAIL: WAIT FOR cannot be executed within a transaction with an
isolation level higher than READ COMMITTED.
postgres=!#
```

That does not match the documented behavior, and I do not think there is
a reason to allow WAIT FOR in such a transaction before the snapshot is
taken.

--
Sami Imseih
Amazon Web Services (AWS)

Attachment Content-Type Size
v1-0001-Reject-WAIT-FOR-earlier-in-transaction-snapshot-m.patch application/octet-stream 3.1 KB

Browse pgsql-hackers by date

  From Date Subject
Next Message Masahiko Sawada 2026-09-08 20:08:46 Re: REPACK (CONCURRENTLY) rewrites tables marked with user_catalog_table
Previous Message Nathan Bossart 2026-09-08 19:49:12 Re: convert various variables to atomics