agora inbox for pgsql-committers@postgresql.org  
help / color / mirror / Atom feed
From: Michael Paquier <michael@paquier.xyz>
To: pgsql-committers@lists.postgresql.org
Subject: pgsql: Improve checks and error messages of pgstat_register_kind()
Date: Mon, 06 Jul 2026 01:50:04 +0000
Message-ID: <E1wgYTE-001WNL-2F@gemulon.postgresql.org> (raw)

Improve checks and error messages of pgstat_register_kind()

pgstat_register_kind() did not validate that required callbacks are
set, which could lead to NULL pointer dereferences when trying to
register a stats kind.  This adds a couple of checks:
- Fox fixed-sized kinds, init_shmem_cb, reset_all_cb, and snapshot_cb
are required.
- For variable-sized kinds, flush_pending_cb is called when there is
pending data, pending_size being required.

These issues should be easy to notice for someone developing an
extension that relies on the custom pgstats APIs.  No backpatch is done
as it is mainly a life improvement.

Author: Sami Imseih <samimseih@gmail.com>
Discussion: https://postgr.es/m/CAA5RZ0uNoe=xT7QsU1K0mMRg-QAwPtupPWZ2J3weM2PjVL2tiA@mail.gmail.com

Branch
------
master

Details
-------
https://git.postgresql.org/pg/commitdiff/a924407ce0264ccb8fcea0de9c6f0573d24b57a7

Modified Files
--------------
src/backend/utils/activity/pgstat.c | 34 +++++++++++++++++++++++++++++-----
1 file changed, 29 insertions(+), 5 deletions(-)



Message-ID: <E1wgYTE-001WNL-2F@gemulon.postgresql.org>
Permalink:  ../E1wgYTE-001WNL-2F@gemulon.postgresql.org/
Also on:    postgresql.org/message-id/E1wgYTE-001WNL-2F@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: Improve checks and error messages of pgstat_register_kind()
  In-Reply-To: <E1wgYTE-001WNL-2F@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