v3-0002-Add-WalRcvGetState-function-to-retrieve-walreceiv.patch

application/octet-stream

Filename: v3-0002-Add-WalRcvGetState-function-to-retrieve-walreceiv.patch
Type: application/octet-stream
Part: 0
Message: Re: BUG #19093: Behavioral change in walreceiver termination between PostgreSQL 14.17 and 14.18

Patch

Same data as JSON: GET /api/v1/attachments/:id/patch the parsed metadata as JSON — format, series position, per-file stats; never the diff bytes. API reference →
Format: format-patch
Series: patch v3-0002
Subject: Add WalRcvGetState() function to retrieve walreceiver state
File+
src/backend/replication/walreceiverfuncs.c 16 0
src/include/replication/walreceiver.h 1 0
From d1489ff2727d0268ea81ce9c7ae4e6f17ad94911 Mon Sep 17 00:00:00 2001
From: alterego655 <824662526@qq.com>
Date: Fri, 31 Oct 2025 18:25:30 +0800
Subject: [PATCH v3 2/3] Add WalRcvGetState() function to retrieve walreceiver
 state

This function provides a thread-safe way to read the walreceiver's current state.
---
 src/backend/replication/walreceiverfuncs.c | 16 ++++++++++++++++
 src/include/replication/walreceiver.h      |  1 +
 2 files changed, 17 insertions(+)

diff --git a/src/backend/replication/walreceiverfuncs.c b/src/backend/replication/walreceiverfuncs.c
index 8de2886ff0b..126e1644d12 100644
--- a/src/backend/replication/walreceiverfuncs.c
+++ b/src/backend/replication/walreceiverfuncs.c
@@ -119,6 +119,22 @@ WalRcvRunning(void)
 		return false;
 }
 
+/*
+ * Return the current 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);
-- 
2.51.0