From 2d38870be86200deefb9979b9dd0a164d5986499 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?=C3=81lvaro=20Herrera?= <alvherre@alvh.no-ip.org>
Date: Thu, 28 Nov 2024 13:11:20 +0100
Subject: [PATCH] Fix synchronized_standby_slots GUC check hook

It requires an LWLock, so it cannot run in processes without PGPROC.
Skip it there; it makes no difference.

Reported-by: Gabriele Bartolini <gabriele.bartolini@enterprisedb.com>
---
 src/backend/replication/slot.c | 16 +++++++---------
 1 file changed, 7 insertions(+), 9 deletions(-)

diff --git a/src/backend/replication/slot.c b/src/backend/replication/slot.c
index 77bae536915..b6e43c1a89e 100644
--- a/src/backend/replication/slot.c
+++ b/src/backend/replication/slot.c
@@ -2428,18 +2428,16 @@ validate_sync_standby_slots(char *rawname, List **elemlist)
 	{
 		GUC_check_errdetail("List syntax is invalid.");
 	}
-	else if (!ReplicationSlotCtl)
+	else if (MyProc)
 	{
 		/*
-		 * We cannot validate the replication slot if the replication slots'
-		 * data has not been initialized. This is ok as we will anyway
-		 * validate the specified slot when waiting for them to catch up. See
-		 * StandbySlotsHaveCaughtup() for details.
+		 * Check that the specified slots exist and are logical slots.  Note
+		 * that because we need an LWLock, we cannot do this on processes
+		 * without a PGPROC (hello syslogger!) so we skip it there, but it
+		 * doesn't have an effect for those anyway.
+		 *
+		 * See StandbySlotsHaveCaughtup() for details.
 		 */
-	}
-	else
-	{
-		/* Check that the specified slots exist and are logical slots */
 		LWLockAcquire(ReplicationSlotControlLock, LW_SHARED);
 
 		foreach_ptr(char, name, *elemlist)
-- 
2.39.5

