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 <[email protected]>
Discussion: 
https://postgr.es/m/CAA5RZ0uNoe=xt7qsu1k0mmrg-qawptuppwz2j3wem2pjvl2...@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(-)

Reply via email to