1
0
mirror of https://github.com/postgres/postgres.git synced 2026-01-27 21:43:08 +03:00

Extend xlogwait infrastructure with write and flush wait types

Add support for waiting on WAL write and flush LSNs in addition to the
existing replay LSN wait type. This provides the foundation for
extending the WAIT FOR command with MODE parameter.

Key changes are following.
- Add WAIT_LSN_TYPE_STANDBY_WRITE and WAIT_LSN_TYPE_STANDBY_FLUSH to
  WaitLSNType.
- Add GetCurrentLSNForWaitType() to retrieve the current LSN for each wait
  type.
- Add new wait events WAIT_EVENT_WAIT_FOR_WAL_WRITE and
  WAIT_EVENT_WAIT_FOR_WAL_FLUSH for pg_stat_activity visibility.
- Update WaitForLSN() to use GetCurrentLSNForWaitType() internally.

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>
This commit is contained in:
Alexander Korotkov
2026-01-05 19:40:31 +02:00
parent d51a5d8e56
commit 7a39f43d88
6 changed files with 93 additions and 28 deletions

View File

@@ -1,7 +1,7 @@
/*-------------------------------------------------------------------------
*
* xlogwait.h
* Declarations for LSN replay waiting routines.
* Declarations for WAL flush, write, and replay waiting routines.
*
* Copyright (c) 2025-2026, PostgreSQL Global Development Group
*
@@ -35,11 +35,16 @@ typedef enum
*/
typedef enum WaitLSNType
{
WAIT_LSN_TYPE_REPLAY, /* Waiting for replay on standby */
WAIT_LSN_TYPE_FLUSH, /* Waiting for flush on primary */
/* Standby wait types (walreceiver/startup wakes) */
WAIT_LSN_TYPE_STANDBY_REPLAY,
WAIT_LSN_TYPE_STANDBY_WRITE,
WAIT_LSN_TYPE_STANDBY_FLUSH,
/* Primary wait types (WAL writer/backends wake) */
WAIT_LSN_TYPE_PRIMARY_FLUSH,
} WaitLSNType;
#define WAIT_LSN_TYPE_COUNT (WAIT_LSN_TYPE_FLUSH + 1)
#define WAIT_LSN_TYPE_COUNT (WAIT_LSN_TYPE_PRIMARY_FLUSH + 1)
/*
* WaitLSNProcInfo - the shared memory structure representing information
@@ -97,6 +102,7 @@ extern PGDLLIMPORT WaitLSNState *waitLSNState;
extern Size WaitLSNShmemSize(void);
extern void WaitLSNShmemInit(void);
extern XLogRecPtr GetCurrentLSNForWaitType(WaitLSNType lsnType);
extern void WaitLSNWakeup(WaitLSNType lsnType, XLogRecPtr currentLSN);
extern void WaitLSNCleanup(void);
extern WaitLSNResult WaitForLSN(WaitLSNType lsnType, XLogRecPtr targetLSN,