From a9f328eee0cec4d0db677b69f3c94eeec8525230 Mon Sep 17 00:00:00 2001
From: Masahiko Sawada <sawada.mshk@gmail.com>
Date: Fri, 25 Sep 2026 10:45:37 -0700
Subject: [PATCH v4 1/2] Add an init callback for the logical decoding control
 data.

LogicalDecodingCtl had no init callback so there is no guarantee that
its fields are initialized. Its startup function
StartupLogicalDecodingStatus() also returns wihtout touching the
fields when wal_level is 'minimal'.

Intialize them in an init callback explcitly. This is not a bug fix
but we just shouldn't be depending on the allocator by accident.

Backpatch to v19, where logicalctl.c was introduced.

Reviewed-by:
Discussion: https://postgr.es/m/CAM527d_eV_BAYFiQnfZLSPfHoihye=nOi-OnAM_57pdH+F+gfA@mail.gmail.com
Backpatch-through: 19
---
 src/backend/replication/logical/logicalctl.c | 10 ++++++++++
 1 file changed, 10 insertions(+)

diff --git a/src/backend/replication/logical/logicalctl.c b/src/backend/replication/logical/logicalctl.c
index 642d965bd1c..fd4ab5f7508 100644
--- a/src/backend/replication/logical/logicalctl.c
+++ b/src/backend/replication/logical/logicalctl.c
@@ -100,9 +100,11 @@ typedef struct LogicalDecodingCtlData
 static LogicalDecodingCtlData *LogicalDecodingCtl = NULL;
 
 static void LogicalDecodingCtlShmemRequest(void *arg);
+static void LogicalDecodingCtlShmemInit(void *arg);
 
 const ShmemCallbacks LogicalDecodingCtlShmemCallbacks = {
 	.request_fn = LogicalDecodingCtlShmemRequest,
+	.init_fn = LogicalDecodingCtlShmemInit,
 };
 
 /*
@@ -136,6 +138,14 @@ LogicalDecodingCtlShmemRequest(void *arg)
 		);
 }
 
+static void
+LogicalDecodingCtlShmemInit(void *arg)
+{
+	LogicalDecodingCtl->xlog_logical_info = false;
+	LogicalDecodingCtl->logical_decoding_enabled = false;
+	LogicalDecodingCtl->pending_disable = false;
+}
+
 /*
  * Initialize the logical decoding status in shmem at server startup. This
  * must be called ONCE during postmaster or standalone-backend startup.
-- 
2.55.0

