Re: 回复: Fix segfault while accessing half-initialized hash table in pgstat_shmem.c - Mailing list pgsql-hackers

From Michael Paquier
Subject Re: 回复: Fix segfault while accessing half-initialized hash table in pgstat_shmem.c
Date
Msg-id aL6LqMup8ykgRh6w@paquier.xyz
Whole thread Raw
In response to Re: 回复: Fix segfault while accessing half-initialized hash table in pgstat_shmem.c  (Michael Paquier <michael@paquier.xyz>)
List pgsql-hackers
On Sat, Sep 06, 2025 at 10:01:24AM +0900, Michael Paquier wrote:
> A last thing that I was not able to spend much time on is how much it
> is possible to mess up with the shared memory state.  If it is worse
> than I suspected initially, where an OOM in a first session can cause
> crashes because of incorrect dshash entries in shmem depending on the
> stats kind fetched, a backpatch will be required, indeed.  The change
> is not really invasive, so that's OK on this side.

OK, I have played a bit more with all that, corrupting the shared
hashtable of pgstats.  At the end, I have used a version close to what
I have sent previously that changes pgstat_init_entry() to return NULL
on OOM with dsa_allocate_extended(), as any other possible errors that
could happen in this call involve elog(ERROR) and not-reachable cases.

pgstat_read_statsfile() has been changed to raise an ERROR instead,
which is what we did previously, giving priority to the on-disk stats
when the environment is under memory pressure at startup.  The patch
has required a few tweaks in the back-branches, nothing huge.

Thanks for the report!
--
Michael

Attachment

pgsql-hackers by date:

Previous
From: Dean Rasheed
Date:
Subject: Re: Add xicorr(X, Y): support for the xi (ξ) correlation coefficient by Chatterjee
Next
From: Eric Marsden
Date:
Subject: doc patch: protocol major.minor numbers in NegotiateProtocolVersion message