Add pg_stat_kind_info system view
Tristan Partin <tristan@partin.io>
From: "Tristan Partin" <tristan@partin.io>
To: "pgsql-hackers" <pgsql-hackers@postgresql.org>
Cc: "Michael Paquier" <michael@paquier.xyz>, "Bertrand Drouvot"
<bertranddrouvot.pg@gmail.com>
Date: 2026-04-30T17:47:59Z
Lists: pgsql-hackers
Hey hackers, In 7949d959458[0], we introduced pluggable cumulative statistics. Extensions could now register their own custom statistics. However, there was no way for an extension author to introspect their custom statistics through SQL, and I don't believe there is currently a way to introspect builtin statistics either. Additionally, there was no way to know how much shared memory each statistics kind was using. We could only know the total shared memory used by the statistics subsystem. dbltap@postgres=# SELECT * FROM pg_shmem_allocations WHERE name = 'Shared Memory Stats'; name | off | size | allocated_size ---------------------+-----------+--------+---------------- Shared Memory Stats | 153456640 | 321976 | 321976 In this patch, I have added a new system view: pg_stat_kind_info built on a new function pg_stat_get_kind_info(). The view has the following columns: - id: id of the statistics kind - name: name of the statistics kind - count: number of entries for the statistics kind - builtin: whether the statistics kind of builtin or not - shared_size: shared memory size of each entry dbltap@postgres=# SELECT * FROM pg_stat_kind_info; id | name | count | builtin | shared_size ----+-------------------------+--------+---------+------------- 1 | database | (null) | t | 288 2 | relation | (null) | t | 248 3 | function | (null) | t | 56 4 | replslot | (null) | t | 120 5 | subscription | (null) | t | 120 6 | backend | (null) | t | 2952 7 | archiver | 1 | t | 0 8 | bgwriter | 1 | t | 0 9 | checkpointer | 1 | t | 0 10 | io | 1 | t | 0 11 | lock | 1 | t | 0 12 | slru | 1 | t | 0 13 | wal | 1 | t | 0 25 | test_custom_var_stats | 0 | f | 40 26 | test_custom_fixed_stats | 1 | f | 56 (15 rows) I am not sure that shared_size is a good column name, and I needed to include pgstat_internal.h in pgstatfuncs.c to get everything working. I'm also curious to hear if anyone thinks there is other valuable information to expose. [0]: https://github.com/postgres/postgres/commit/7949d9594582ab49dee221e1db1aa5401ace49d4 -- Tristan Partin PostgreSQL Contributors Team AWS (https://aws.amazon.com)
Commits
Same data as JSON:
GET /api/v1/messages/:b64id/commits
the thread's linked commits as JSON, with link sources.
API reference →
-
Add system view pg_stat_kind_info
- 3b066de6c0a1 master landed
-
Introduce pluggable APIs for Cumulative Statistics
- 7949d9594582 18.0 cited