EXEC_BACKEND on Linux leads to failures when processes try to attach
to shared memory if kernel.randomize_va_space != 0. There is a comment
in the source code explaining this, but it is far from where the error
occurs.

This patch introduces a comment navigating the programmer to the explanation.
From 91eab4909b76adf13cb8961ba1f3b5616e895e0e Mon Sep 17 00:00:00 2001
From: Ivan Kovmir <[email protected]>
Date: Thu, 13 Nov 2025 14:49:29 +0100
Subject: [PATCH 1/1] Explain possible shared memory re-attach failure

---
 src/backend/port/win32_shmem.c | 4 ++++
 1 file changed, 4 insertions(+)

diff --git a/src/backend/port/win32_shmem.c b/src/backend/port/win32_shmem.c
index 4dee856d6bd..d530aa39712 100644
--- a/src/backend/port/win32_shmem.c
+++ b/src/backend/port/win32_shmem.c
@@ -440,6 +440,10 @@ PGSharedMemoryReAttach(void)
 		elog(FATAL, "failed to release reserved memory region (addr=%p): error code %lu",
 			 UsedShmemSegAddr, GetLastError());
 
+	/*
+	 * If this fails on Linux, set sysctl kernel.randomize_va_space = 0
+	 * See comment in SubPostmasterMain().
+	 */
 	hdr = (PGShmemHeader *) MapViewOfFileEx(UsedShmemSegID, FILE_MAP_READ | FILE_MAP_WRITE, 0, 0, 0, UsedShmemSegAddr);
 	if (!hdr)
 		elog(FATAL, "could not reattach to shared memory (key=%p, addr=%p): error code %lu",
-- 
2.51.2

Reply via email to