1
0
mirror of https://github.com/postgres/postgres.git synced 2025-07-28 23:42:10 +03:00

Add backend-level statistics to pgstats

This adds a new variable-numbered statistics kind in pgstats, where the
object ID key of the stats entries is based on the proc number of the
backends.  This acts as an upper-bound for the number of stats entries
that can exist at once.  The entries are created when a backend starts
after authentication succeeds, and are removed when the backend exits,
making the stats entry exist for as long as their backend is up and
running.  These are not written to the pgstats file at shutdown (note
that write_to_file is disabled, as a safety measure).

Currently, these stats include only information about the I/O generated
by a backend, using the same layer as pg_stat_io, except that it is now
possible to know how much activity is happening in each backend rather
than an overall aggregate of all the activity.  A function called
pg_stat_get_backend_io() is added to access this data depending on the
PID of a backend.  The existing structure could be expanded in the
future to add more information about other statistics related to
backends, depending on requirements or ideas.

Auxiliary processes are not included in this set of statistics.  These
are less interesting to have than normal backends as they have dedicated
entries in pg_stat_io, and stats kinds of their own.

This commit includes also pg_stat_reset_backend_stats(), function able
to reset all the stats associated to a single backend.

Bump catalog version and PGSTAT_FILE_FORMAT_ID.

Author: Bertrand Drouvot
Reviewed-by: Álvaro Herrera, Kyotaro Horiguchi, Michael Paquier, Nazir
Bilal Yavuz
Discussion: https://postgr.es/m/ZtXR+CtkEVVE/LHF@ip-10-97-1-34.eu-west-3.compute.internal
This commit is contained in:
Michael Paquier
2024-12-19 13:19:22 +09:00
parent ff7c40d7fd
commit 9aea73fc61
18 changed files with 552 additions and 28 deletions

View File

@ -8403,9 +8403,11 @@ COPY postgres_log FROM '/full/path/to/logfile.csv' WITH csv;
displayed in <link linkend="monitoring-pg-stat-database-view">
<structname>pg_stat_database</structname></link>,
<link linkend="monitoring-pg-stat-io-view">
<structname>pg_stat_io</structname></link>, in the output of
<xref linkend="sql-explain"/> when the <literal>BUFFERS</literal> option
is used, in the output of <xref linkend="sql-vacuum"/> when
<structname>pg_stat_io</structname></link>, in the output of the
<link linkend="pg-stat-get-backend-io">
<function>pg_stat_get_backend_io()</function></link> function, in the
output of <xref linkend="sql-explain"/> when the <literal>BUFFERS</literal>
option is used, in the output of <xref linkend="sql-vacuum"/> when
the <literal>VERBOSE</literal> option is used, by autovacuum
for auto-vacuums and auto-analyzes, when <xref
linkend="guc-log-autovacuum-min-duration"/> is set and by

View File

@ -4790,6 +4790,27 @@ description | Waiting for a newly initialized WAL file to reach durable storage
</para></entry>
</row>
<row>
<entry id="pg-stat-get-backend-io" role="func_table_entry"><para role="func_signature">
<indexterm>
<primary>pg_stat_get_backend_io</primary>
</indexterm>
<function>pg_stat_get_backend_io</function> ( <type>integer</type> )
<returnvalue>setof record</returnvalue>
</para>
<para>
Returns I/O statistics about the backend with the specified
process ID. The output fields are exactly the same as the ones in the
<structname>pg_stat_io</structname> view.
</para>
<para>
The function does not return I/O statistics for the checkpointer,
the background writer, the startup process and the autovacuum launcher
as they are already visible in the <structname>pg_stat_io</structname>
view and there is only one of each.
</para></entry>
</row>
<row>
<entry role="func_table_entry"><para role="func_signature">
<indexterm>
@ -4971,6 +4992,24 @@ description | Waiting for a newly initialized WAL file to reach durable storage
</para></entry>
</row>
<row>
<entry role="func_table_entry"><para role="func_signature">
<indexterm>
<primary>pg_stat_reset_backend_stats</primary>
</indexterm>
<function>pg_stat_reset_backend_stats</function> ( <type>integer</type> )
<returnvalue>void</returnvalue>
</para>
<para>
Resets statistics for a single backend with the specified process ID
to zero.
</para>
<para>
This function is restricted to superusers by default, but other users
can be granted EXECUTE to run the function.
</para></entry>
</row>
<row>
<entry role="func_table_entry"><para role="func_signature">
<indexterm>