From: | Nathan Bossart <nathandbossart(at)gmail(dot)com> |
---|---|
To: | Sami Imseih <samimseih(at)gmail(dot)com> |
Cc: | pgsql-hackers <pgsql-hackers(at)postgresql(dot)org> |
Subject: | Re: shmem_startup_hook called twice on Windows |
Date: | 2025-08-15 15:20:00 |
Message-ID: | aJ9QIF3g2QQko9wq@nathan |
Views: | Whole Thread | Raw Message | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-hackers |
On Fri, Aug 15, 2025 at 09:17:22AM -0500, Sami Imseih wrote:
> While working on a related area, I noticed that shmem_startup_hook
> is called twice under EXEC_BACKEND.
>
> The first call occurs in CreateSharedMemoryAndSemaphores() during
> postmaster startup (!IsUnderPostmaster), which is expected.
>
> The second call happens in AttachSharedMemoryStructs() (when
> EXEC_BACKEND is defined), and this occurs in normal backends
> (IsUnderPostmaster).
>
> The second call does not seem correct. The startup hook that should
> only run during
> postmaster initialization, AFAIK.
>
> Blame shows that this change was introduced in commit 69d903367c,
> but I could not determine the rationale from the discussion,
> so it may have been an oversight.
I think the startup hook must run in each backend for EXEC_BACKEND, else we
won't properly initialize pointers to shared memory in that case, right?
I added the following wording in commit 964152c:
+ <literal>shmem_startup_hook</literal> provides a convenient place for the
+ initialization code, but it is not strictly required that all such code
+ be placed in this hook. Each backend will execute the registered
+ <literal>shmem_startup_hook</literal> shortly after it attaches to shared
+ memory. Note that add-ins should still acquire
+ <function>AddinShmemInitLock</function> within this hook, as shown in the
+ example above.
IIUC commit 69d9033 actually makes that inaccurate for the non-EXEC_BACKEND
case. Presumably this is okay because we don't need to re-initialize
pointers to shmem when forking. I must've missed this change when updating
the documentation.
--
nathan
From | Date | Subject | |
---|---|---|---|
Next Message | Sami Imseih | 2025-08-15 15:33:31 | Re: shmem_startup_hook called twice on Windows |
Previous Message | Tom Lane | 2025-08-15 15:16:46 | Re: Compilation issues for HASH_STATISTICS and HASH_DEBUG options |