Hi,
On 2023-06-16 10:01:33 +0900, Michael Paquier wrote:
> + /*
> + * If we haven't connected to a database yet, don't attribute time to
> + * "shared state" (InvalidOid is used to track stats for shared relations
> + * etc).
> + */
> + if (!OidIsValid(MyDatabaseId))
> + return;
>
> Hmm. pgstat_report_stat() is called by standby_redo() for a
> XLOG_RUNNING_XACTS record so this would prevent the startup process
> from doing any stats updates for the shared db state, no?
Hm. Effectively the startup process isn't doing that in a useful way
today. Commit/Rollback and session stats don't make sense, and block
read/write time are wrongly attributed.
I think it'd take a fair amount of work to track these stats in a more useful
manner for the startup process, by virtue of it effectively being connected to
multiple databases. We'd need to track
pgStatBlockReadTime/pgStatBlockWriteTime on a per-database level, which
wouldn't be easy to do without increasing overhead.
Greetings,
Andres Freund