Re: Prevent crash when calling pgstat functions with unregistered stats kind - Mailing list pgsql-hackers

From Michael Paquier
Subject Re: Prevent crash when calling pgstat functions with unregistered stats kind
Date
Msg-id akXebziFr_eQgQi8@paquier.xyz
Whole thread
In response to Re: Prevent crash when calling pgstat functions with unregistered stats kind  (Bertrand Drouvot <bertranddrouvot.pg@gmail.com>)
Responses Re: Prevent crash when calling pgstat functions with unregistered stats kind
List pgsql-hackers
On Thu, Jul 02, 2026 at 03:27:18AM +0000, Bertrand Drouvot wrote:
> On Wed, Jul 01, 2026 at 04:20:39PM +0800, Ewan Young wrote:
>> One small thing: in pgstat_snapshot_fixed(), the existing
>> Assert(pgstat_is_kind_valid(kind)); becomes redundant after the new NULL
>> check. A non-NULL kind_info already implies the kind is valid (that's the
>> only way pgstat_get_kind_info() returns non-NULL), so the assert can never
>> fire. Might as well drop it and keep just the fixed_amount one.
>
> Yeah good catch, done in the attached.

I am not convinced that it is worth bothering in the core code about
this class of failures; they are just not interesting, and impossible
to miss.

It seems to me that this error is in the _PG_init() of the modules in
modules/test_custom_stats/: we should not bypass the
pgstat_register_kind() if not loading the library from
shared_preload_libraries, but let the call happen and fail.
--
Michael

Attachment

pgsql-hackers by date:

Previous
From: "zengman"
Date:
Subject: Re: (SQL/PGQ) Clean up orphaned properties when dropping a label
Next
From: Bertrand Drouvot
Date:
Subject: Re: Prevent crash when calling pgstat functions with unregistered stats kind