On Mon, Mar 31, 2025 at 07:42:19AM +0000, Bertrand Drouvot wrote:
> I think we can simply move the pgstat_fetch_stat_backend() call at the end
> of pgstat_fetch_stat_backend_by_pid(), like in the attached. With this in place
> the issue is fixed on my side.
>
> Thoughts?
Confirmed. I agree that it is simpler to move all the accesses to
beentry before attempting to retrieve the pgstats entry.
One thing that itched me a bit in the patch is that we would set
bktype even if we don't have a pgstats entry. The two callers of
pgstat_fetch_stat_backend_by_pid() return tuples full of NULLs and
zeros in this case, discarding the backend type automatically, but
let's keep the API consistent and set the value to B_INVALID if
pgstat_fetch_stat_backend() returns NULL.
I have added a comment warning about not accessing beentry when
fetching the backend pgstats entry, and applied the result. Thanks
for the report, Alexander, and for the patch, Bertrand.
--
Michael