agora inbox for pgsql-committers@postgresql.org
help / color / mirror / Atom feedFrom: Michael Paquier <michael@paquier.xyz>
To: pgsql-committers@lists.postgresql.org
Subject: pgsql: Allocate pgstats entry body before insert into shared hashtable
Date: Wed, 23 Sep 2026 23:51:11 +0000
Message-ID: <E1x9Wk3-00000000zEb-3B6C@gemulon.postgresql.org> (raw)
Allocate pgstats entry body before insert into shared hashtable
8191e0c16a03 made pgstat_init_entry() return NULL on DSA allocation
failure so callers could delete a just-inserted hash entry. That works
when dsa_allocate_extended(DSA_ALLOC_NO_OOM) returns InvalidDsaPointer,
but not when the creation of a new DSM segment raises ERROR.
Under this type of failure, pgstat_init_entry() would mark the hash
entry live before allocating the body and cause an inconsistent state in
shared memory. The next backend trying to acquire the existing,
partially-initialized entry in pgstat_acquire_entry_ref() would crash,
taking down the server. Some of the public reports mentioned ENOSPC on
POSIX shared memory as one initial cause.
This commit refactors the pgstats entry initialization to happen in two
phases:
- Allocate the DSA chunk.
- Insert the hash entry with a valid segment.
If a concurrent insert wins, the allocation of the first phase needs an
extra set of dsa_free() calls (pulling back a DSM into its free list).
As this changes the signature of pgstat_init_entry(), no backpatch is
done.
Author: Yuriy Grigoryev <ju.grigorev@ftdata.ru>
Author: Michael Paquier <michael@paquier.xyz>
Discussion: https://postgr.es/m/ddc3ecfb01ce4e9698b23cc59767f016@localhost.localdomain
Branch
------
master
Details
-------
https://git.postgresql.org/pg/commitdiff/d9de60c5e47a7f7a5dcee050d119bda08ea85d55
Modified Files
--------------
src/backend/utils/activity/pgstat.c | 46 ++++++++++++++------
src/backend/utils/activity/pgstat_shmem.c | 72 ++++++++++++++++++-------------
src/include/utils/pgstat_internal.h | 4 +-
3 files changed, 76 insertions(+), 46 deletions(-)
Message-ID: <E1x9Wk3-00000000zEb-3B6C@gemulon.postgresql.org>
Permalink: ../E1x9Wk3-00000000zEb-3B6C@gemulon.postgresql.org/
Also on: postgresql.org/message-id/E1x9Wk3-00000000zEb-3B6C@gemulon.postgresql.org
reply
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Reply to all the recipients using the --to and --cc options:
reply via email
To: pgsql-committers@postgresql.org
Cc: michael@paquier.xyz, pgsql-committers@lists.postgresql.org
Subject: Re: pgsql: Allocate pgstats entry body before insert into shared hashtable
In-Reply-To: <E1x9Wk3-00000000zEb-3B6C@gemulon.postgresql.org>
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
This inbox is served by agora; see mirroring instructions
for how to clone and mirror all data and code used for this inbox