Add WalRcvGetState() to retrieve the state of a WAL receiver
authorMichael Paquier <michael@paquier.xyz>
Tue, 4 Nov 2025 03:57:36 +0000 (12:57 +0900)
committerMichael Paquier <michael@paquier.xyz>
Tue, 4 Nov 2025 03:57:36 +0000 (12:57 +0900)
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

src/backend/replication/walreceiverfuncs.c
src/include/replication/walreceiver.h

index 8de2886ff0b59b0909a74a381ac40876598e1ce2..6a693d854c49394b809995163035905ba451e382 100644 (file)
@@ -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)?
index 89f63f908f8a81a46e6ffe1b0341e2dd5db4358c..e5557d21fa828c52f1f3c0299a23c141279cba52 100644 (file)
@@ -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);