Re: per backend WAL statistics - Mailing list pgsql-hackers

From Michael Paquier
Subject Re: per backend WAL statistics
Date
Msg-id Z_MiVq-HzPlMS7Q_@paquier.xyz
Whole thread Raw
In response to Re: per backend WAL statistics  (Bertrand Drouvot <bertranddrouvot.pg@gmail.com>)
List pgsql-hackers
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

Attachment

pgsql-hackers by date:

Previous
From: Greg Sabino Mullane
Date:
Subject: Re: Logging which local address was connected to in log_line_prefix
Next
From: Daniel Gustafsson
Date:
Subject: Re: Possibly hard-to-read message