pg.ddx.io  pgsql-committers@postgresql.org mailing list archive  
help / color / mirror / Atom feed
pgsql: Add the MODE option to the WAIT FOR LSN command
2+ messages / 2 participants
[nested] [flat]

Commits from this thread:
  2026-01-20 30776ca468  Remove redundant pg_unreachable() after elog(ERROR) from ExecWaitStmt()
* pgsql: Add the MODE option to the WAIT FOR LSN command
@ 2026-01-05 17:56 Alexander Korotkov <akorotkov@postgresql.org>
  2026-01-19 16:26 ` Re: pgsql: Add the MODE option to the WAIT FOR LSN command Peter Eisentraut <peter@eisentraut.org>
  0 siblings, 1 reply; 2+ messages in thread

From: Alexander Korotkov @ 2026-01-05 17:56 UTC (permalink / raw)
  To: pgsql-committers@lists.postgresql.org

Add the MODE option to the WAIT FOR LSN command

This commit extends the WAIT FOR LSN command with an optional MODE option in
the WITH clause that specifies which LSN type to wait for:

  WAIT FOR LSN '<lsn>' [WITH (MODE '<mode>', ...)]

where mode can be:
 - 'standby_replay' (default): Wait for WAL to be replayed to the specified
   LSN,
 - 'standby_write': Wait for WAL to be written (received) to the specified
   LSN,
 - 'standby_flush': Wait for WAL to be flushed to disk at the specified LSN,
 - 'primary_flush': Wait for WAL to be flushed to disk on the primary server.

The default mode is 'standby_replay', matching the original behavior when MODE
is not specified. This follows the pattern used by COPY and EXPLAIN
commands, where options are specified as string values in the WITH clause.

Modes are explicitly named to distinguish between primary and standby
operations:
- Standby modes ('standby_replay', 'standby_write', 'standby_flush') can only
  be used during recovery (on a standby server),
- Primary mode ('primary_flush') can only be used on a primary server.

The 'standby_write' and 'standby_flush' modes are useful for scenarios where
applications need to ensure WAL has been received or persisted on the standby
without necessarily waiting for replay to complete. The 'primary_flush' mode
allows waiting for WAL to be flushed on the primary server.

This commit also includes includes:
- Documentation updates for the new syntax and mode descriptions,
- Test coverage for all four modes, including error cases and concurrent
  waiters,
- Wakeup logic in walreceiver for standby write/flush waiters,
- Wakeup logic in WAL writer for primary flush waiters.

Discussion: https://postgr.es/m/CABPTF7UiArgW-sXj9CNwRzUhYOQrevLzkYcgBydmX5oDes1sjg%40mail.gmail.com
Author: Xuneng Zhou <xunengzhou@gmail.com>
Reviewed-by: Alexander Korotkov <aekorotkov@gmail.com>
Reviewed-by: Chao Li <li.evan.chao@gmail.com>
Reviewed-by: Alvaro Herrera <alvherre@kurilemu.de>

Branch
------
master

Details
-------
https://git.postgresql.org/pg/commitdiff/49a181b5d634340fcfb7c762c387c03f6405367e

Modified Files
--------------
doc/src/sgml/ref/wait_for.sgml          | 213 +++++++++++++----
src/backend/access/transam/xlog.c       |  22 +-
src/backend/commands/wait.c             | 174 ++++++++++++--
src/backend/replication/walreceiver.c   |  18 ++
src/test/recovery/t/049_wait_for_lsn.pl | 411 +++++++++++++++++++++++++++++---
5 files changed, 741 insertions(+), 97 deletions(-)



^ permalink  raw  reply  [nested|flat] 2+ messages in thread

* Re: pgsql: Add the MODE option to the WAIT FOR LSN command
  2026-01-05 17:56 pgsql: Add the MODE option to the WAIT FOR LSN command Alexander Korotkov <akorotkov@postgresql.org>
@ 2026-01-19 16:26 ` Peter Eisentraut <peter@eisentraut.org>
  0 siblings, 0 replies; 2+ messages in thread

From: Peter Eisentraut @ 2026-01-19 16:26 UTC (permalink / raw)
  To: Alexander Korotkov <akorotkov@postgresql.org>; pgsql-committers@lists.postgresql.org

On 05.01.26 18:56, Alexander Korotkov wrote:
> Add the MODE option to the WAIT FOR LSN command

> Details
> -------
> https://git.postgresql.org/pg/commitdiff/49a181b5d634340fcfb7c762c387c03f6405367e
> 
> Modified Files
> --------------
> doc/src/sgml/ref/wait_for.sgml          | 213 +++++++++++++----
> src/backend/access/transam/xlog.c       |  22 +-
> src/backend/commands/wait.c             | 174 ++++++++++++--
> src/backend/replication/walreceiver.c   |  18 ++
> src/test/recovery/t/049_wait_for_lsn.pl | 411 +++++++++++++++++++++++++++++---
> 5 files changed, 741 insertions(+), 97 deletions(-)

This patch adds several instances in src/backend/commands/wait.c where 
an elog(ERROR) is followed immediately by pg_unreachable().  I think 
this is redundant.  I think this pattern has been used historically in 
functions that return non-void where the elog(ERROR) is the last call, 
to avoid warnings about a missing return.  But in this case, the 
function returns void.  Check please if this is really necessary or just 
copy-and-pasted.






^ permalink  raw  reply  [nested|flat] 2+ messages in thread


end of thread, other threads:[~2026-01-19 16:26 UTC | newest]

Thread overview: 2+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2026-01-05 17:56 pgsql: Add the MODE option to the WAIT FOR LSN command Alexander Korotkov <akorotkov@postgresql.org>
2026-01-19 16:26 ` Peter Eisentraut <peter@eisentraut.org>

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox