public inbox for [email protected]  
help / color / mirror / Atom feed
From: Fujii Masao <[email protected]>
To: PostgreSQL Hackers <[email protected]>
Subject: Release postmaster working memory context in slotsync worker
Date: Sat, 28 Feb 2026 01:25:12 +0900
Message-ID: <CAHGQGwHO05JaUpgKF8FBDmPdBUJsK22axRRcgmAUc2Jyi8OK8g@mail.gmail.com> (raw)

Hi,

Child processes do not need the postmaster's working memory context and
release it at the start of their main function. However, the slotsync worker
appears to have missed this step.

To avoid this unnecessary memory usage, I'd like to propose that the slotsync
worker release the postmaster's working memory context at startup.
A patch is attached.

Currently, pg_log_backend_memory_contexts() reports the following
postmaster-related memory contexts in the slotsync worker:

    LOG:  level: 2; Postmaster: 21984 total in 2 blocks; 5600 free (7
chunks); 16384 used
    LOG:  level: 3; ident parser context: 1024 total in 1 blocks; 784
free (0 chunks); 240 used
    LOG:  level: 3; hba parser context: 25600 total in 6 blocks; 9864
free (11 chunks); 15736 used

With the attached patch, these contexts are no longer present.

Regards,

-- 
Fujii Masao


Attachments:

  [application/octet-stream] v1-0001-Release-postmaster-working-memory-context-in-slot.patch (1.2K, 2-v1-0001-Release-postmaster-working-memory-context-in-slot.patch)
  download | inline diff:
From c40c231a45078c8f749b200fb036b4700509efbd Mon Sep 17 00:00:00 2001
From: Fujii Masao <[email protected]>
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



view thread (2+ messages)  latest in thread

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients using the --to and --cc options:
  reply via email

  To: [email protected]
  Cc: [email protected], [email protected]
  Subject: Re: Release postmaster working memory context in slotsync worker
  In-Reply-To: <CAHGQGwHO05JaUpgKF8FBDmPdBUJsK22axRRcgmAUc2Jyi8OK8g@mail.gmail.com>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by agora; see mirroring instructions
for how to clone and mirror all data and code used for this inbox