1
0
mirror of https://github.com/postgres/postgres.git synced 2026-10-23 13:29:09 +03:00

Fix ShmemInitStruct() reattachment in single-user mode

ShmemInitStruct() only looked for an existing allocation when
IsUnderPostmaster was true.  Because of that, you could not reattach
to an existing shmem area in a standalone backend.

Usually, you only call ShmemInitStruct() for the same shmem area once
in a process and hold onto the returned pointer, but there was no rule
that you couldn't call it twice for the same area if you wanted to,
and before commit 283e823f9d, it worked.  To fix, check for an
existing allocation regardless of process type, like the old
implementation did.

Author: Ayush Tiwari <ayushtiwari.slg01@gmail.com>
Reviewed-by: Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
Discusssion: https://www.postgresql.org/message-id/CAJTYsWXREGXCnWdZJsXt8pT2UY_Y2GSx+HOUu2X3s8YDCLj0_A@mail.gmail.com
Backpatch-through: 19
This commit is contained in:
Heikki Linnakangas
2026-09-24 18:20:32 +03:00
parent 89829354de
commit 4e277b424a

View File

@@ -1131,12 +1131,8 @@ ShmemInitStruct(const char *name, Size size, bool *foundPtr)
LWLockAcquire(ShmemIndexLock, LW_EXCLUSIVE);
/*
* During postmaster startup, look up the existing entry if any.
*/
*foundPtr = false;
if (IsUnderPostmaster)
*foundPtr = AttachShmemIndexEntry(&request, true);
/* Look up the existing entry if any */
*foundPtr = AttachShmemIndexEntry(&request, true);
/* Initialize it if not found */
if (!*foundPtr)