diff options
| author | Michael Paquier <michael@paquier.xyz> | 2025-11-04 12:57:36 +0900 |
|---|---|---|
| committer | Michael Paquier <michael@paquier.xyz> | 2025-11-04 12:57:36 +0900 |
| commit | e0ca61e7c4d55c34d67a3cc6fa0bdea2f41d2cf2 (patch) | |
| tree | 288580385b939c818993f17c0c9f4654f8bdaa0f /src | |
| parent | 17b2d5ec759c0d26b29def7e57f51d0515ddca1f (diff) | |
Add WalRcvGetState() to retrieve the state of a WAL receiver
This has come up as useful as an alternative of WalRcvStreaming(), to be
able to do sanity checks based on the state of a WAL receiver. This
will be used in a follow-up commit.
Author: Xuneng Zhou <xunengzhou@gmail.com>
Discussion: https://postgr.es/m/19093-c4fff49a608f82a0@postgresql.org
Diffstat (limited to 'src')
| -rw-r--r-- | src/backend/replication/walreceiverfuncs.c | 14 | ||||
| -rw-r--r-- | src/include/replication/walreceiver.h | 1 |
2 files changed, 15 insertions, 0 deletions
diff --git a/src/backend/replication/walreceiverfuncs.c b/src/backend/replication/walreceiverfuncs.c index 8de2886ff0b..6a693d854c4 100644 --- a/src/backend/replication/walreceiverfuncs.c +++ b/src/backend/replication/walreceiverfuncs.c @@ -119,6 +119,20 @@ WalRcvRunning(void) return false; } +/* Return the state of the walreceiver. */ +WalRcvState +WalRcvGetState(void) +{ + WalRcvData *walrcv = WalRcv; + WalRcvState state; + + SpinLockAcquire(&walrcv->mutex); + state = walrcv->walRcvState; + SpinLockRelease(&walrcv->mutex); + + return state; +} + /* * Is walreceiver running and streaming (or at least attempting to connect, * or starting up)? diff --git a/src/include/replication/walreceiver.h b/src/include/replication/walreceiver.h index 89f63f908f8..e5557d21fa8 100644 --- a/src/include/replication/walreceiver.h +++ b/src/include/replication/walreceiver.h @@ -495,6 +495,7 @@ extern void WalRcvShmemInit(void); extern void ShutdownWalRcv(void); extern bool WalRcvStreaming(void); extern bool WalRcvRunning(void); +extern WalRcvState WalRcvGetState(void); extern void RequestXLogStreaming(TimeLineID tli, XLogRecPtr recptr, const char *conninfo, const char *slotname, bool create_temp_slot); |
