Implement WAIT FOR command
authorAlexander Korotkov <[email protected]>
Wed, 5 Nov 2025 09:43:55 +0000 (11:43 +0200)
committerAlexander Korotkov <[email protected]>
Wed, 5 Nov 2025 09:44:13 +0000 (11:44 +0200)
commit447aae13b0305780e87cac7b0dd669db6fab3d9d
tree2ba9e956343d3f85d9d91011220047b8e80d6171
parent3b4e53a075ea5671b075f8fd873241179f8e64af
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@mail.gmail.com
Discussion: https://www.postgresql.org/message-id/flat/CABPTF7UNft368x-RgOXkfj475OwEbp%2BVVO-wEXz7StgjD_%3D6sw%40mail.gmail.com
Author: Kartyshov Ivan <[email protected]>
Author: Alexander Korotkov <[email protected]>
Author: Xuneng Zhou <[email protected]>
Reviewed-by: Michael Paquier <[email protected]>
Reviewed-by: Peter Eisentraut <[email protected]>
Reviewed-by: Dilip Kumar <[email protected]>
Reviewed-by: Amit Kapila <[email protected]>
Reviewed-by: Alexander Lakhin <[email protected]>
Reviewed-by: Bharath Rupireddy <[email protected]>
Reviewed-by: Euler Taveira <[email protected]>
Reviewed-by: Heikki Linnakangas <[email protected]>
Reviewed-by: Kyotaro Horiguchi <[email protected]>
Reviewed-by: jian he <[email protected]>
Reviewed-by: Álvaro Herrera <[email protected]>
Reviewed-by: Xuneng Zhou <[email protected]>
21 files changed:
doc/src/sgml/high-availability.sgml
doc/src/sgml/ref/allfiles.sgml
doc/src/sgml/ref/wait_for.sgml [new file with mode: 0644]
doc/src/sgml/reference.sgml
src/backend/access/transam/xact.c
src/backend/access/transam/xlog.c
src/backend/access/transam/xlogrecovery.c
src/backend/commands/Makefile
src/backend/commands/meson.build
src/backend/commands/wait.c [new file with mode: 0644]
src/backend/parser/gram.y
src/backend/storage/lmgr/proc.c
src/backend/tcop/pquery.c
src/backend/tcop/utility.c
src/include/commands/wait.h [new file with mode: 0644]
src/include/nodes/parsenodes.h
src/include/parser/kwlist.h
src/include/tcop/cmdtaglist.h
src/test/recovery/meson.build
src/test/recovery/t/049_wait_for_lsn.pl [new file with mode: 0644]
src/tools/pgindent/typedefs.list