Re: per backend I/O statistics

Michael Paquier <michael@paquier.xyz>

From: Michael Paquier <michael@paquier.xyz>
To: Bertrand Drouvot <bertranddrouvot.pg@gmail.com>
Cc: Nazir Bilal Yavuz <byavuz81@gmail.com>, Alvaro Herrera <alvherre@alvh.no-ip.org>, Kyotaro Horiguchi <horikyota.ntt@gmail.com>, pgsql-hackers@lists.postgresql.org
Date: 2024-11-20T00:01:26Z
Lists: pgsql-hackers
On Tue, Nov 19, 2024 at 04:28:55PM +0000, Bertrand Drouvot wrote:
> So, for the startup process only, what about?
> 
> - don't call pgstat_create_backend_stat() in pgstat_beinit()...
> - but call it in StartupXLOG() instead (after the stats are discarded or restored).
> 
> That way we could get rid of the changes linked to the assertion and still handle
> the startup process particular case. Thoughts?

Hmm.  That may prove to be a good idea in the long-term.  The startup
process is a specific path kicked in at a very early stage, so it is
also a bit weird that we'd try to insert statistics while we are going
to reset them anyway a bit later.  That may also be relevant for
custom statistics, actually, especially if some calls happen in some
hook paths taken before the reset is done.  This could happen for
injection point stats when loading it with shared_preload_libraries, 
actually, if you load, attach or run a callback at this early stage.
The existing sanity checks are a safety net that we should not change
or adapt for specific stats kinds conditions, IMO.  Perhaps this had
better be done as a patch of its own, on top of the rest.

> Yeah that's the reason why I suggested "pgstat_backend.c". I would not be
> surprised if we add more "per backend" stats (that are not I/O related) in the
> future as the main machinery would be there.

Okay.
--
Michael

Commits

  1. Rework handling of pending data for backend statistics

  2. Rename some pgstats callbacks related to flush of entries

  3. Relax regression test for fsync check of backend-level stats

  4. Add backend-level statistics to pgstats

  5. Extract logic filling pg_stat_get_io()'s tuplestore into its own routine

  6. Tweak some comments related to variable-numbered stats in pgstat.c