postgres.git / summary / log / commit / refs

commit    9ac2cb07b44f56a9185c08dafbba0ece74e8fcab
Author:   Heikki Linnakangas <heikki.linnakangas@iki.fi>
Date:     Thu Sep 24 15:20:32 2026 +0000
First released in: 19.0

    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


src/backend/storage/ipc/shmem.c | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/src/backend/storage/ipc/shmem.c b/src/backend/storage/ipc/shmem.c index 99cf27216ca..85ecb5b6d8f 100644 --- a/src/backend/storage/ipc/shmem.c +++ b/src/backend/storage/ipc/shmem.c @@ -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) [parent: dae3463fa969]