Re: Reject WAIT FOR earlier in transaction-snapshot mode

From: Xuneng Zhou <xunengzhou(at)gmail(dot)com>
To: Sami Imseih <samimseih(dot)pg(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 14:00:55
Message-ID: CABPTF7XTHSX0mxDpCTTogtt0AMS3rtJ82xFe8Yic_t3wa=4e2Q@mail.gmail.com
Views: Whole Thread | Raw Message | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

On Wed, Sep 9, 2026 at 9:25 PM Sami Imseih <samimseih(dot)pg(at)gmail(dot)com> wrote:
>
> 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=!#

V2 LGTM. Do you prefer to keep the snapshot and isolation-level checks
next to each other?

--
Regards,
Xuneng Zhou
HighGo Software Co., Ltd.

In response to

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Fujii Masao 2026-09-09 14:02:26 postgres_fdw: Fix crash when estimating joins with functions
Previous Message Sami Imseih 2026-09-09 13:57:05 Re: Improve WAIT FOR read-your-writes consistency doc