Re: Reject WAIT FOR earlier in transaction-snapshot mode

From: Sami Imseih <samimseih(dot)pg(at)gmail(dot)com>
To: Xuneng Zhou <xunengzhou(at)gmail(dot)com>
Cc: Postgres hackers <pgsql-hackers(at)lists(dot)postgresql(dot)org>
Subject: Re: Reject WAIT FOR earlier in transaction-snapshot mode
Date: 2026-09-09 13:25:25
Message-ID: CAN12+YL=5a24oTYSj_Qs0Y80spS0MDwX5egcriXBqdHgpGiX4Q@mail.gmail.com
Views: Whole Thread | Raw Message | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

Hi,

Thanks for the review.

> BEGIN ISOLATION LEVEL READ COMMITTED;
> DECLARE c CURSOR FOR SELECT 1;
> WAIT FOR LSN '0/0';
> -- ERROR: WAIT FOR must be called without an active or registered snapshot
>
> BEGIN ISOLATION LEVEL READ COMMITTED;
> SELECT pg_export_snapshot();
> WAIT FOR LSN '0/0';
> -- ERROR: WAIT FOR must be called without an active or registered snapshot

This means there is a bug in the ERROR message DETAIL. Thanks for pointing
this out.

```
postgres=# begin;
BEGIN
postgres=*# DECLARE c CURSOR FOR SELECT 1;
DECLARE CURSOR
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=!#
```

So I fixed this by first checking the isolation level and using "WAIT
FOR cannot be executed ... READ COMMITTED"
as the errmsg. The existing snapshot check must come after that.

I also added tests to cover the three relevant cases: READ COMMITTED
with a snapshot, and
REPEATABLE READ both with and without a snapshot. The REPEATABLE
READ-with-snapshot
case was already covered, but its expected error message needed to be updated.

The results looks like this:

```
postgres=# BEGIN ISOLATION LEVEL REPEATABLE READ;
BEGIN
postgres=*# select 1;
?column?
----------
1
(1 row)

postgres=*# WAIT FOR LSN '0/0' WITH (mode 'PRIMARY_FLUSH');
ERROR: WAIT FOR cannot be executed within a transaction with an
isolation level higher than READ COMMITTED
postgres=!#
```

```
postgres=# BEGIN ISOLATION LEVEL REPEATABLE READ;
BEGIN
postgres=*# WAIT FOR LSN '0/0' WITH (mode 'PRIMARY_FLUSH');
ERROR: WAIT FOR cannot be executed within a transaction with an
isolation level higher than READ COMMITTED
postgres=!#
```

```
postgres=# BEGIN;
BEGIN
postgres=*# DECLARE c CURSOR FOR SELECT 1;
DECLARE CURSOR
postgres=*#
postgres=*# WAIT FOR LSN '0/0' WITH (mode 'PRIMARY_FLUSH');
ERROR: WAIT FOR must be called without an active or registered snapshot
postgres=!#
```

--
Sami

Attachment Content-Type Size
v2-0001-Fix-WAIT-FOR-rejection-errors.patch application/octet-stream 4.5 KB

In response to

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Nikolay Samokhvalov 2026-09-09 13:31:01 Re: Add contrib module pg_stat_log: cumulative statistics about server log messages
Previous Message Matthias van de Meent 2026-09-09 13:04:53 Re: Init connection time grows quadratically