Re: [PATCH] Two remaining shmem attachment issues in single-user mode - Mailing list pgsql-hackers

From Heikki Linnakangas
Subject Re: [PATCH] Two remaining shmem attachment issues in single-user mode
Date
Msg-id 35d8c7cf-3d55-4d19-b236-27669e1146fb@iki.fi
Whole thread
In response to Re: [PATCH] Two remaining shmem attachment issues in single-user mode  (Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>)
Responses Re: [PATCH] Two remaining shmem attachment issues in single-user mode
List pgsql-hackers
On 24/09/2026 16:07, Ashutosh Bapat wrote:
> On Wed, Sep 23, 2026 at 6:50 PM Ayush Tiwari
> <ayushtiwari.slg01@gmail.com> wrote:
>>
>> On Wed, 23 Sept 2026 at 17:53, Heikki Linnakangas <hlinnaka@iki.fi> wrote:
>>>
>>> On 19/09/2026 22:12, Ayush Tiwari wrote:
>>>> The other one is a bit odd: ask for an existing area with
>>>> SHMEM_ATTACH_UNKNOWN_SIZE after startup in single-user mode, and we
>>>> tell you it "cannot be used during startup".
>>>>
>>>> IIUC, the distinction we need here is whether we're still working out
>>>> the initial shmem requirements, not whether we have a postmaster.
>>>> 0002 adds SRS_REQUESTING_AFTER_STARTUP for that. I couldn't see a clean
>>>> way to reuse SRS_REQUESTING without mixing those cases up.
>>>>
>>>> I'm a bit on the fence about adding another state just for this.
>>>> With the PG19 release getting close, I thought I'd send this out for
>>>> feedback before spending more time iterating on it. Does the extra
>>>> state seem like the right approach?
>>>
>>> Extra state sounds reasonable. Thanks, I'll take a closer look, and I'll
>>> double-check all the other places in shmem.c where we use
>>> IsUnderPostmaster, too.
>>>
>>> The IsUnderPostmaster variable is deceptive. It's easy to forget about
>>> single-user code, and incorrectly assume that IsUnderPostmaster == true
>>> means you're a backend and IsUnderPostmaster == false means you're
>>> postmaster. I think that's what happened to me here and with the
>>> previous single-user mode bugs. I remember I've struggled to keep that
>>> in mind in the past too. We should perhaps replace IsUnderPostmaster
>>> with a three-valued enum or something (postmaster, backend, single-user
>>> backend).
> 
> If we do this, do we still need extra state?

I came up with a simpler idea: we can check "ShmemIndex == NULL" to know 
if shared memory has already been initialized and we're in the "after 
startup" case, or not. That feels like a pretty direct way of checking 
for exactly the property we care about, without needing another state.

I also reworked the tests. I added a very generic test_shmem_register() 
function that [registers a callback that] calls ShmemRequestStruct() 
with given name and size. And then the perl script can call it with 
different sizes, to test the "unknown-size" case, as well as trying to 
attach with incorrect size etc. So most of the logic is now in the perl 
script.

What do you think?

- Heikki

Attachment

pgsql-hackers by date:

Previous
From: "Jonathan S. Katz"
Date:
Subject: Re: add list of major features to the v19 release notes
Next
From: Dmitry Dolgov
Date:
Subject: Re: [PATCH] Add ALTER SYSTEM RELOAD