pgsql: Implement WAIT FOR command

From: Alexander Korotkov <akorotkov(at)postgresql(dot)org>
To: pgsql-committers(at)lists(dot)postgresql(dot)org
Subject: pgsql: Implement WAIT FOR command
Date: 2025-11-05 09:44:46
Message-ID: E1vGa4M-0058H1-2k@gemulon.postgresql.org
Views: Whole Thread | Raw Message | Download mbox | Resend email
Thread:
Lists: pgsql-committers pgsql-hackers

Implement WAIT FOR command

WAIT FOR is to be used on standby and specifies waiting for
the specific WAL location to be replayed. This option is useful when
the user makes some data changes on primary and needs a guarantee to see
these changes are on standby.

WAIT FOR needs to wait without any snapshot held. Otherwise, the snapshot
could prevent the replay of WAL records, implying a kind of self-deadlock.
This is why separate utility command seems appears to be the most robust
way to implement this functionality. It's not possible to implement this as
a function. Previous experience shows that stored procedures also have
limitation in this aspect.

Discussion: https://www.postgresql.org/message-id/flat/CAPpHfdsjtZLVzxjGT8rJHCYbM0D5dwkO+BBjcirozJ6nYbOW8Q(at)mail(dot)gmail(dot)com
Discussion: https://www.postgresql.org/message-id/flat/CABPTF7UNft368x-RgOXkfj475OwEbp%2BVVO-wEXz7StgjD_%3D6sw%40mail.gmail.com
Author: Kartyshov Ivan <i(dot)kartyshov(at)postgrespro(dot)ru>
Author: Alexander Korotkov <aekorotkov(at)gmail(dot)com>
Author: Xuneng Zhou <xunengzhou(at)gmail(dot)com>
Reviewed-by: Michael Paquier <michael(at)paquier(dot)xyz>
Reviewed-by: Peter Eisentraut <peter(dot)eisentraut(at)enterprisedb(dot)com>
Reviewed-by: Dilip Kumar <dilipbalaut(at)gmail(dot)com>
Reviewed-by: Amit Kapila <amit(dot)kapila16(at)gmail(dot)com>
Reviewed-by: Alexander Lakhin <exclusion(at)gmail(dot)com>
Reviewed-by: Bharath Rupireddy <bharath(dot)rupireddyforpostgres(at)gmail(dot)com>
Reviewed-by: Euler Taveira <euler(at)eulerto(dot)com>
Reviewed-by: Heikki Linnakangas <hlinnaka(at)iki(dot)fi>
Reviewed-by: Kyotaro Horiguchi <horikyota(dot)ntt(at)gmail(dot)com>
Reviewed-by: jian he <jian(dot)universality(at)gmail(dot)com>
Reviewed-by: Álvaro Herrera <alvherre(at)kurilemu(dot)de>
Reviewed-by: Xuneng Zhou <xunengzhou(at)gmail(dot)com>

Branch
------
master

Details
-------
https://git.postgresql.org/pg/commitdiff/447aae13b0305780e87cac7b0dd669db6fab3d9d

Modified Files
--------------
doc/src/sgml/high-availability.sgml | 54 ++++++
doc/src/sgml/ref/allfiles.sgml | 1 +
doc/src/sgml/ref/wait_for.sgml | 234 +++++++++++++++++++++++
doc/src/sgml/reference.sgml | 1 +
src/backend/access/transam/xact.c | 6 +
src/backend/access/transam/xlog.c | 7 +
src/backend/access/transam/xlogrecovery.c | 11 ++
src/backend/commands/Makefile | 3 +-
src/backend/commands/meson.build | 1 +
src/backend/commands/wait.c | 212 +++++++++++++++++++++
src/backend/parser/gram.y | 33 +++-
src/backend/storage/lmgr/proc.c | 6 +
src/backend/tcop/pquery.c | 12 +-
src/backend/tcop/utility.c | 22 +++
src/include/commands/wait.h | 22 +++
src/include/nodes/parsenodes.h | 8 +
src/include/parser/kwlist.h | 2 +
src/include/tcop/cmdtaglist.h | 1 +
src/test/recovery/meson.build | 3 +-
src/test/recovery/t/049_wait_for_lsn.pl | 302 ++++++++++++++++++++++++++++++
src/tools/pgindent/typedefs.list | 1 +
21 files changed, 931 insertions(+), 11 deletions(-)

Responses

Browse pgsql-committers by date

  From Date Subject
Next Message Peter Eisentraut 2025-11-05 15:38:52 pgsql: doc: Add section for temporal tables
Previous Message Richard Guo 2025-11-05 09:16:25 pgsql: Fix assertion failure in generate_orderedappend_paths()

Browse pgsql-hackers by date

  From Date Subject
Next Message David Rowley 2025-11-05 09:44:58 Re: Teaching planner to short-circuit empty UNION/EXCEPT/INTERSECT inputs
Previous Message shveta malik 2025-11-05 09:41:20 Re: Logical Replication of sequences