From c40c231a45078c8f749b200fb036b4700509efbd Mon Sep 17 00:00:00 2001
From: Fujii Masao <fujii@postgresql.org>
Date: Sat, 28 Feb 2026 00:50:11 +0900
Subject: [PATCH v1] Release postmaster working memory context in slotsync
 worker.

Child processes do not need the postmaster's working memory context and
normally release it at the start of their main entry point. However,
the slotsync worker forgot to do so.

This commit makes the slotsync worker release the postmaster's working memory
context at startup, avoiding unnecessary memory usage in that process.
---
 src/backend/replication/logical/slotsync.c | 7 +++++++
 1 file changed, 7 insertions(+)

diff --git a/src/backend/replication/logical/slotsync.c b/src/backend/replication/logical/slotsync.c
index 062a08ccb88..4c05d1a98db 100644
--- a/src/backend/replication/logical/slotsync.c
+++ b/src/backend/replication/logical/slotsync.c
@@ -1480,6 +1480,13 @@ ReplSlotSyncWorkerMain(const void *startup_data, size_t startup_data_len)
 
 	Assert(startup_data_len == 0);
 
+	/* Release postmaster's working memory context */
+	if (PostmasterContext)
+	{
+		MemoryContextDelete(PostmasterContext);
+		PostmasterContext = NULL;
+	}
+
 	init_ps_display(NULL);
 
 	Assert(GetProcessingMode() == InitProcessing);
-- 
2.51.2

