| From: | Sami Imseih <samimseih(at)gmail(dot)com> |
|---|---|
| To: | pgsql-hackers <pgsql-hackers(at)postgresql(dot)org> |
| Subject: | pgstat: allow a stats kind to use its own dedicated dsa/dshash |
| Date: | 2026-07-15 17:16:26 |
| Message-ID: | CAA5RZ0supQBxSkh=CWB39=j+cL3hHcLPki3tcBk0B1r4fesg_g@mail.gmail.com |
| Views: | Whole Thread | Raw Message | Download mbox | Resend email |
| Thread: | |
| Lists: | pgsql-hackers |
Hi,
As I have been working on [1] in which pg_stat_statements can use
a custom cumulative stats kind, I realized it will be beneficial for a
kind to have a dedicated dsa area/dshash in which to store their stats.
A kind like pg_stat_statements will have thousands of entries and
likely will have more entries than all other kinds combined. If combined
in the same dsa/dshash with everything else, sequential scans looking
for pg_stat_statements entries will have to skip over all other kinds,
and vice versa. A dedicated hash also reduces lock contention on
unrelated kinds, particularly for garbage-collection.
There is also a need for custom kinds to independently size their own
dsa areas, so they can manage them carefully. If we want to set limits
on how much space the entries can use for a kind like pg_stat_statements,
we need to be able to set the size directly on its dsa.
The attached proposal implements a new stats kind option, own_hash, which
when set to true allocates an independent dsa/dshash for that stats kind.
Also, 2 new external APIs are introduced:
- pgstat_get_hash_for_kind(PgStat_Kind kind)
- pgstat_get_dsa_for_kind(PgStat_Kind kind)
These allow the extension to retrieve the dshash and dsa pointers for
both iterating through the entries and for setting the size limit on
the dsa. Otherwise, the management of these separate structures is
transparent to the extension and managed by the pgstat infrastructure.
These APIs are necessary because we don't have higher-level abstractions
in pgstats to do things like "iterate through this kind" or "set size
limit for this stats kind"; such abstractions may be good to have to
avoid using dshash_seq_* or dsa_set_size_limit directly, but I am not
sure they are worth it at this point.
Only variable-length stats can opt into own_hash. Fixed-length allocates their
data into PgStat_ShmemControl.
--
Sami Imseih
Amazon Web Services (AWS)
| Attachment | Content-Type | Size |
|---|---|---|
| v1-0001-pgstat-allow-a-stats-kind-to-use-its-own-dedicate.patch | application/octet-stream | 41.3 KB |
| From | Date | Subject | |
|---|---|---|---|
| Next Message | Paul A Jungwirth | 2026-07-15 17:17:50 | Re: Enforce INSERT RLS checks for FOR PORTION OF leftovers? |
| Previous Message | Nisha Moond | 2026-07-15 16:48:47 | Re: Support EXCEPT for TABLES IN SCHEMA publications |