Re: Fix a wal_debug crash with the new shmem allocation API - Mailing list pgsql-hackers

From Bharath Rupireddy
Subject Re: Fix a wal_debug crash with the new shmem allocation API
Date
Msg-id CALj2ACWUzOmgTHQ++eBkZSczH=v4LMOBXHPOXvMwbtpAL5NuuQ@mail.gmail.com
Whole thread
In response to Re: Fix a wal_debug crash with the new shmem allocation API  (Heikki Linnakangas <hlinnaka@iki.fi>)
Responses Re: Fix a wal_debug crash with the new shmem allocation API
List pgsql-hackers
Hi,

On Thu, Oct 8, 2026 at 3:07 AM Heikki Linnakangas <hlinnaka@iki.fi> wrote:
>
> Hmm, it's a bit ugly to initialize what is a purely backend-private
> thing in the ShmemInit/Attach() functions. It was expedient in the past,
> because the ShmemInit() functions happened to run at the right times,
> but initializing the memory context was never related to shared memory
> in any way. I propose the attached, which calls the InitWalDebug()
> function from InitXLogInsert() instead.

Thanks. Yes, this fix is better than mine. Since the wal_debug memory
context is only used while inserting WAL records, moving it to the WAL
insert working buffers initialization code is correct. The patch LGTM.

> Searching for similar cases where we do backend-private initialization
> that is not related to shared memory in the shmem callbacks, I found
> BufferManagerShmemAttach():
>
> > static void
> > BufferManagerShmemAttach(void *arg)
> > {
> >    /* Initialize per-backend file flush context */
> >    WritebackContextInit(&BackendWritebackContext,
> >                         &backend_flush_after);
> > }
>
> There's no bug here, but I propose that we also move that to
> InitBufferManagerAccess(), per the second attached patch.

Moving the per-backend file flush context to the buffer pool access
init function looks good to me. Do we need to keep
BackendWritebackContext as extern? A quick check on
https://sourcegraph.com says no, but just in case any external module
needs it.

--
Bharath Rupireddy
Amazon Web Services: https://aws.amazon.com



pgsql-hackers by date:

Previous
From: Masahiko Sawada
Date:
Subject: Re: Parallel vacuum: I/O timings in the log leave out the parallel workers
Next
From: Andrey Borodin
Date:
Subject: Re: Do we want to solve reload/config races more generally? (was: Postmaster crashes on SIGHUP when oauth_validator_libraries holds only whitespace)