Home Explore Blog CI



postgresql

60th chunk of `doc/src/sgml/monitoring.sgml`
993bc5f91b48094e20be2250a32a652d3c530af4779e35680000000100000fb0
 <literal>serializable</literal>,
        <literal>subtransaction</literal>, or
        <literal>transaction</literal>
        to reset the counters for only that entry.
        If the argument is <literal>other</literal> (or indeed, any
        unrecognized name), then the counters for all other SLRU caches, such
        as extension-defined caches, are reset.
       </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>
          <primary>pg_stat_reset_replication_slot</primary>
        </indexterm>
        <function>pg_stat_reset_replication_slot</function> ( <type>text</type> )
        <returnvalue>void</returnvalue>
       </para>
       <para>
        Resets statistics of the replication slot defined by the argument. If
        the argument is <literal>NULL</literal>, resets statistics for all
        the replication slots.
       </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>
          <primary>pg_stat_reset_subscription_stats</primary>
        </indexterm>
        <function>pg_stat_reset_subscription_stats</function> ( <type>oid</type> )
        <returnvalue>void</returnvalue>
       </para>
       <para>
        Resets statistics for a single subscription shown in the
        <structname>pg_stat_subscription_stats</structname> view to zero. If
        the argument is <literal>NULL</literal>, reset statistics for all
        subscriptions.
       </para>
       <para>
        This function is restricted to superusers by default, but other users
        can be granted EXECUTE to run the function.
       </para></entry>
      </row>
     </tbody>
    </tgroup>
   </table>

  <warning>
   <para>
    Using <function>pg_stat_reset()</function> also resets counters that
    autovacuum uses to determine when to trigger a vacuum or an analyze.
    Resetting these counters can cause autovacuum to not perform necessary
    work, which can cause problems such as table bloat or out-dated
    table statistics.  A database-wide <command>ANALYZE</command> is
    recommended after the statistics have been reset.
   </para>
  </warning>

  <para>
   <function>pg_stat_get_activity</function>, the underlying function of
   the <structname>pg_stat_activity</structname> view, returns a set of records
   containing all the available information about each backend process.
   Sometimes it may be more convenient to obtain just a subset of this
   information.  In such cases, another set of per-backend statistics
   access functions can be used; these are shown in <xref
   linkend="monitoring-stats-backend-funcs-table"/>.
   These access functions use the session's backend ID number, which is a
   small integer (>= 0) that is distinct from the backend ID of any
   concurrent session, although a session's ID can be recycled as soon as
   it exits.  The backend ID is used, among other things, to identify the
   session's temporary schema if it has one.
   The function <function>pg_stat_get_backend_idset</function> provides a
   convenient way to list all the active backends' ID numbers for
   invoking these functions.  For example, to show the <acronym>PID</acronym>s and
   current queries of all backends:

<programlisting>
SELECT pg_stat_get_backend_pid(backendid) AS pid,
       pg_stat_get_backend_activity(backendid) AS query
FROM pg_stat_get_backend_idset() AS backendid;
</programlisting>
  </para>

   <table id="monitoring-stats-backend-funcs-table">
    <title>Per-Backend Statistics Functions</title>
    <tgroup cols="1">
     <thead>
      <row>
       <entry role="func_table_entry"><para

Title: PostgreSQL Statistics Functions: Replication Slots, Subscriptions, and Backend Statistics
Summary
This section continues the description of statistic reset functions, focusing on `pg_stat_reset_replication_slot` (resets statistics for a specific replication slot or all slots) and `pg_stat_reset_subscription_stats` (resets statistics for a subscription or all subscriptions). It also warns about resetting autovacuum counters and suggests running ANALYZE afterward. Furthermore, it introduces per-backend statistics functions like `pg_stat_get_activity` and `pg_stat_get_backend_idset` for accessing information about individual backend processes, along with an example query showing how to retrieve PIDs and current queries of all backends.