Home Explore Blog CI



postgresql

61th chunk of `doc/src/sgml/monitoring.sgml`
b7b519997cb7a4ec1b33fffe6ae2506d8268f21f6b070a910000000100000fa3
 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 role="func_signature">
        Function
       </para>
       <para>
        Description
       </para></entry>
      </row>
     </thead>

     <tbody>
      <row>
       <entry role="func_table_entry"><para role="func_signature">
        <indexterm>
         <primary>pg_stat_get_backend_activity</primary>
        </indexterm>
        <function>pg_stat_get_backend_activity</function> ( <type>integer</type> )
        <returnvalue>text</returnvalue>
       </para>
       <para>
        Returns the text of this backend's most recent query.
       </para></entry>
      </row>

      <row>
       <entry role="func_table_entry"><para role="func_signature">
        <indexterm>
         <primary>pg_stat_get_backend_activity_start</primary>
        </indexterm>
        <function>pg_stat_get_backend_activity_start</function> ( <type>integer</type> )
        <returnvalue>timestamp with time zone</returnvalue>
       </para>
       <para>
        Returns the time when the backend's most recent query was started.
       </para></entry>
      </row>

      <row>
       <entry role="func_table_entry"><para role="func_signature">
        <indexterm>
         <primary>pg_stat_get_backend_client_addr</primary>
        </indexterm>
        <function>pg_stat_get_backend_client_addr</function> ( <type>integer</type> )
        <returnvalue>inet</returnvalue>
       </para>
       <para>
        Returns the IP address of the client connected to this backend.
       </para></entry>
      </row>

      <row>
       <entry role="func_table_entry"><para role="func_signature">
        <indexterm>
         <primary>pg_stat_get_backend_client_port</primary>
        </indexterm>
        <function>pg_stat_get_backend_client_port</function> ( <type>integer</type> )
        <returnvalue>integer</returnvalue>
       </para>
       <para>
        Returns the TCP port number that the client is using for communication.
       </para></entry>
      </row>

      <row>
       <entry role="func_table_entry"><para role="func_signature">
        <indexterm>
         <primary>pg_stat_get_backend_dbid</primary>
        </indexterm>
        <function>pg_stat_get_backend_dbid</function> ( <type>integer</type> )
        <returnvalue>oid</returnvalue>
       </para>
       <para>
        Returns the OID of the database this backend is connected to.
       </para></entry>
      </row>

      <row>
       <entry role="func_table_entry"><para role="func_signature">
        <indexterm>
         <primary>pg_stat_get_backend_idset</primary>
        </indexterm>
        <function>pg_stat_get_backend_idset</function> ()
        <returnvalue>setof integer</returnvalue>
       </para>
       <para>
        Returns the set of currently active backend ID numbers.
       </para></entry>
      </row>

      <row>
       <entry role="func_table_entry"><para role="func_signature">
        <indexterm>
         <primary>pg_stat_get_backend_pid</primary>
        </indexterm>

Title: Per-Backend Statistics Functions in PostgreSQL
Summary
This section describes a set of per-backend statistics functions in PostgreSQL. These functions use the session's backend ID to retrieve specific information about a backend process. The functions include `pg_stat_get_backend_activity` (returns the most recent query's text), `pg_stat_get_backend_activity_start` (returns the query start time), `pg_stat_get_backend_client_addr` (returns the client IP address), `pg_stat_get_backend_client_port` (returns the client TCP port), `pg_stat_get_backend_dbid` (returns the database OID), `pg_stat_get_backend_idset` (returns the set of active backend IDs).