Re: pgstat: allow a stats kind to use its own dedicated dsa/dshash

From: Sami Imseih <samimseih(dot)pg(at)gmail(dot)com>
To: Michael Paquier <michael(at)paquier(dot)xyz>
Cc: Sami Imseih <samimseih(at)gmail(dot)com>, pgsql-hackers <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: pgstat: allow a stats kind to use its own dedicated dsa/dshash
Date: 2026-10-05 21:13:37
Message-ID: CAN12+YL4jXUFT+uVyfzgdNpM9utg=vM6=z5e8fqU1QWjWGx05w@mail.gmail.com
Views: Whole Thread | Raw Message | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

> Please note that this patch does not apply anymore. Could you rebase,
> please?

Done.

I also addressed some of Bertrand's points.

> === 1
>
> I wonder if this should use
> dshash_find_or_insert_extended(..., DSHASH_INSERT_NO_OOM)
> and release the local entry if it returns NULL?

Done. The insertion paths now use
dshash_find_or_insert_extended(..., DSHASH_INSERT_NO_OOM). In
pgstat_get_entry_ref(), the local entry is released if insertion returns NULL.

> === 4
>
> Current master provides dshash_get_dsa_area() since 762e329e83f, so this one
> looks now redundant.

Done. pgstat_get_dsa_for_kind() now uses

dshash_get_dsa_area(pgstat_get_hash_for_kind(kind))

> === 5
>
> Could pgstat_reset_entries_of_kind() scan only the hash returned by
> pgstat_get_hash_for_kind(kind)?

Done. I added pgstat_reset_matching_entries_in_hash().
pgstat_reset_matching_entries() still scans all hashes by calling that helper
for each hash. pgstat_reset_entries_of_kind() now scans only
pgstat_get_hash_for_kind(kind), instead of scanning all hashes and filtering by
kind.

> === 6
>
> I think the branch should be removed so pgstat_register_kind() reports the
> intended prerequisite error.

Done.

For the other points.

> === 2
>
> I wonder if this case should discard the statistics that no longer fit rather
> than prevent the server from starting?

I left this unchanged for now. Discarding persisted stats instead of failing
startup changes the failure semantics, so I think this needs more discussion.
I also think the existing behavior is sane: either the stats file is loaded, or
it is discarded as a whole.

> === 3
>
> That would retain independent iteration and hash partition locks while avoiding
> an additional shared memory allocation and per backend DSA state when independent
> memory accounting is not needed.

I kept own_hash tied to a dedicated DSA for now. I am not sure we would want to
support that mix and match behavior. A stats kind that asks for its own hash is
already asking to be isolated from the shared stats table, and using a dedicated
DSA keeps the hash storage and entry storage isolated in the same way.

I have not thought of a good use case for splitting those controls, but perhaps
there is one.

Attached is v2

--
Sami Imseih
Amazon Web Services AWS

Attachment Content-Type Size
v2-0001-pgstat-allow-a-stats-kind-to-use-its-own-dedicate.patch application/octet-stream 42.9 KB

In response to

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Matthias van de Meent 2026-10-05 21:23:03 Re: UNDO with constant time recovery (CTR)
Previous Message Andrew Dunstan 2026-10-05 21:05:43 Re: [PG19] COPY (query) TO ... (FORMAT json) uses the table's column names