Add pg_stat_kind_info system view

  • Jump to comment-1
    Tristan Partin<tristan@partin.io>
    Apr 30, 2026, 5:49 PM UTC
    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';
    nameoffsizeallocated_size
    Shared Memory Stats153456640321976321976
    In this patch, I have added a new system view: pgstatkind_info built
    on a new function pgstatgetkindinfo(). 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;
    idnamecountbuiltinshared_size
    1database(null)t288
    2relation(null)t248
    3function(null)t56
    4replslot(null)t120
    5subscription(null)t120
    6backend(null)t2952
    7archiver1t0
    8bgwriter1t0
    9checkpointer1t0
    10io1t0
    11lock1t0
    12slru1t0
    13wal1t0
    25test_custom_var_stats0f40
    26test_custom_fixed_stats1f56
    (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)