pgsql: Fix ShmemInitStruct() reattachment in single-user mode

From: Heikki Linnakangas <heikki(dot)linnakangas(at)iki(dot)fi>
To: pgsql-committers(at)lists(dot)postgresql(dot)org
Subject: pgsql: Fix ShmemInitStruct() reattachment in single-user mode
Date: 2026-09-24 15:22:11
Message-ID: E1x9lH1-000000014n7-3zgt@gemulon.postgresql.org
Views: Whole Thread | Raw Message | Download mbox | Resend email
Thread:
Lists: pgsql-committers

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(dot)slg01(at)gmail(dot)com>
Reviewed-by: Ashutosh Bapat <ashutosh(dot)bapat(dot)oss(at)gmail(dot)com>
Discusssion: https://www.postgresql.org/message-id/CAJTYsWXREGXCnWdZJsXt8pT2UY_Y2GSx+HOUu2X3s8YDCLj0_A@mail.gmail.com
Backpatch-through: 19

Branch
------
REL_19_STABLE

Details
-------
https://git.postgresql.org/pg/commitdiff/9ac2cb07b44f56a9185c08dafbba0ece74e8fcab

Modified Files
--------------
src/backend/storage/ipc/shmem.c | 8 ++------
1 file changed, 2 insertions(+), 6 deletions(-)

Browse pgsql-committers by date

  From Date Subject
Next Message Alexander Korotkov 2026-09-24 15:47:58 pgsql: Revert "JSON_TABLE: propagate table-level ON ERROR to columns pe
Previous Message Heikki Linnakangas 2026-09-24 11:50:12 pgsql: Fix assertion in pg_get_shmem_pagesize() in single-user mode