<!--
doc/src/sgml/ref/pgpool_adm_pcp_proc_info.sgml
Pgpool-II documentation
-->

<refentry id="PGPOOL-ADM-PCP-PROC-INFO">
 <indexterm zone="pgpool-adm-pcp-proc-info">
  <primary>pgpool_adm_pcp_proc_info</primary>
 </indexterm>

 <refmeta>
  <refentrytitle>pgpool_adm_pcp_proc_info</refentrytitle>
  <manvolnum>3</manvolnum>
  <refmiscinfo>pgpool_adm extension</refmiscinfo>
 </refmeta>

 <refnamediv>
  <refname>pgpool_adm_pcp_proc_info</refname>
  <refpurpose>
   a function to display the information
   on <productname>Pgpool-II</productname> child process
   </refpurpose>
 </refnamediv>

 <refsynopsisdiv>
  <funcsynopsis>
   <funcprototype>
    <funcdef><function>pcp_proc_info</function> returns record</funcdef>
    <paramdef>text <parameter>host</parameter></paramdef>
    <paramdef>integer <parameter>port</parameter></paramdef>
    <paramdef>text <parameter>username</parameter></paramdef>
    <paramdef>text <parameter>password</parameter></paramdef>
    <paramdef>out <parameter>database text</parameter></paramdef>
    <paramdef>out <parameter>username text</parameter></paramdef>
    <paramdef>out <parameter>start_time text</parameter></paramdef>
    <paramdef>out <parameter>client_connection_count text</parameter></paramdef>
    <paramdef>out <parameter>major text</parameter></paramdef>
    <paramdef>out <parameter>minor text</parameter></paramdef>
    <paramdef>out <parameter>backend_connection_time text</parameter></paramdef>
    <paramdef>out <parameter>client_connection_time text</parameter></paramdef>
    <paramdef>out <parameter>client_idle_duration text</parameter></paramdef>
    <paramdef>out <parameter>client_disconnection_time text</parameter></paramdef>
    <paramdef>out <parameter>pool_counter text</parameter></paramdef>
    <paramdef>out <parameter>backend_pid text</parameter></paramdef>
    <paramdef>out <parameter>connected text</parameter></paramdef>
    <paramdef>out <parameter>pid text</parameter></paramdef>
    <paramdef>out <parameter>backend_id text</parameter></paramdef>
    <paramdef>out <parameter>status text</parameter></paramdef>
    <paramdef>out <parameter>load_balance_node text</parameter></paramdef>
    <paramdef>out <parameter>client_host text</parameter></paramdef>
    <paramdef>out <parameter>client_port text</parameter></paramdef>
    <paramdef>out <parameter>statement </parameter></paramdef>
   </funcprototype>

   <funcprototype>
    <funcdef><function>pcp_proc_info</function> returns record</funcdef>
    <paramdef>integer <parameter>node_id</parameter></paramdef>
    <paramdef>text <parameter>pcp_server</parameter></paramdef>
    <paramdef>out <parameter>database text</parameter></paramdef>
    <paramdef>out <parameter>username text</parameter></paramdef>
    <paramdef>out <parameter>start_time text</parameter></paramdef>
    <paramdef>out <parameter>client_connection_count text</parameter></paramdef>
    <paramdef>out <parameter>major text</parameter></paramdef>
    <paramdef>out <parameter>minor text</parameter></paramdef>
    <paramdef>out <parameter>backend_connection_time text</parameter></paramdef>
    <paramdef>out <parameter>client_connection_time text</parameter></paramdef>
    <paramdef>out <parameter>client_idle_duration text</parameter></paramdef>
    <paramdef>out <parameter>client_disconnection_time text</parameter></paramdef>
    <paramdef>out <parameter>pool_counter text</parameter></paramdef>
    <paramdef>out <parameter>backend_pid text</parameter></paramdef>
    <paramdef>out <parameter>connected text</parameter></paramdef>
    <paramdef>out <parameter>pid text</parameter></paramdef>
    <paramdef>out <parameter>backend_id text</parameter></paramdef>
    <paramdef>out <parameter>status text</parameter></paramdef>
    <paramdef>out <parameter>load_balance_node text</parameter></paramdef>
    <paramdef>out <parameter>client_host text</parameter></paramdef>
    <paramdef>out <parameter>client_port text</parameter></paramdef>
    <paramdef>out <parameter>statement </parameter></paramdef>
   </funcprototype>

  </funcsynopsis>
 </refsynopsisdiv>

 <refsect1 id="R3-PCP-PROC-INFO-3">
  <title>Description</title>
  <para>
   <function>pcp_proc_info</function>
   displays the information
   on <productname>Pgpool-II</productname> child process.
   All the information is same as <xref linkend="pcp-proc-info">.
   All the data types are "text".
  </para>
 </refsect1>

 <refsect1>
  <title>Arguments</title>
  <para>
   <variablelist>

    <varlistentry>
     <term><replaceable class="parameter">pcp_server</replaceable></term>
     <listitem>
      <para>
       The foreign server name for pcp server.
      </para>
     </listitem>
    </varlistentry>

    <varlistentry>
     <term><option>Other arguments </option></term>
     <listitem>
      <para>
       See <xref linkend="pcp-common-options">.
      </para>
     </listitem>
    </varlistentry>
   </variablelist>
  </para>
 </refsect1>

 <refsect1>
  <title>Example</title>
  <para>
   In the example below a search condition "connected" column = '1' is
   specified, and only the information on the process connected from
   clients. In this psql session pcp_proc_info is called in the from
   clause, and the information is shown on row 1 and 2. The select
   statement is sent to only backend_id = '0' (which is probably the
   primary), and the "status" column of the row 1 is "Execute
   command", the "statement" column shows the select statement which
   was executed. On the other hand the "statement" column of the row 2
   is empty, since the select statement is was not sent to backend_id
   = '1'.
  </para>
  <para>
   The information on the other psql session is shown on the row 2 and
   3.  In this example "select 1" was sent to "backend_id" = '1'
   (probably standby).
   <programlisting>
test=# select * from pcp_proc_info(host => '', port => 11001, username => 't-ishii', password => 't-ishii') where connected = '1';
-[ RECORD 1 ]-------------+----------------------------------------------------------------------------------------------------------------------------
database                  | test
username                  | t-ishii
start_time                | 2025-02-22 20:56:08
client_connection_count   | 0
major                     | 3
minor                     | 0
backend_connection_time   | 2025-02-22 20:58:37
client_connection_time    | 2025-02-22 20:58:37
client_idle_duration      | 0
client_disconnection_time | 
pool_counter              | 1
backend_pid               | 14750
connected                 | 1
pid                       | 14585
backend_id                | 0
status                    | Execute command
load_balance_node         | 1
client_host               | 127.0.0.1
client_port               | 59120
statement                 | select * from pcp_proc_info(host => '', port => 11001, username => 't-ishii', password => 't-ishii') where connected = '1';
-[ RECORD 2 ]-------------+----------------------------------------------------------------------------------------------------------------------------
database                  | test
username                  | t-ishii
start_time                | 2025-02-22 20:56:08
client_connection_count   | 0
major                     | 3
minor                     | 0
backend_connection_time   | 2025-02-22 20:58:37
client_connection_time    | 2025-02-22 20:58:37
client_idle_duration      | 0
client_disconnection_time | 
pool_counter              | 1
backend_pid               | 14751
connected                 | 1
pid                       | 14585
backend_id                | 1
status                    | Execute command
load_balance_node         | 0
client_host               | 127.0.0.1
client_port               | 59120
statement                 | 
-[ RECORD 3 ]-------------+----------------------------------------------------------------------------------------------------------------------------
database                  | test
username                  | t-ishii
start_time                | 2025-02-22 20:56:08
client_connection_count   | 0
major                     | 3
minor                     | 0
backend_connection_time   | 2025-02-22 20:58:56
client_connection_time    | 2025-02-22 20:58:56
client_idle_duration      | 0
client_disconnection_time | 
pool_counter              | 1
backend_pid               | 14767
connected                 | 1
pid                       | 14601
backend_id                | 0
status                    | Idle
load_balance_node         | 0
client_host               | 127.0.0.1
client_port               | 54072
statement                 | 
-[ RECORD 4 ]-------------+----------------------------------------------------------------------------------------------------------------------------
database                  | test
username                  | t-ishii
start_time                | 2025-02-22 20:56:08
client_connection_count   | 0
major                     | 3
minor                     | 0
backend_connection_time   | 2025-02-22 20:58:56
client_connection_time    | 2025-02-22 20:58:56
client_idle_duration      | 0
client_disconnection_time | 
pool_counter              | 1
backend_pid               | 14768
connected                 | 1
pid                       | 14601
backend_id                | 1
status                    | Idle
load_balance_node         | 1
client_host               | 127.0.0.1
client_port               | 54072
statement                 | select 1;
   </programlisting>
  </para>
  <para>
   In the example below we define a function called
   "pgpool_query_info" which shows last executed query in each pgpool
   child process along with associated information: usernae, database,
   client host, client port, pgpool host, pgpool port, pgpool pid,
   backend host, backend port, backend pid, backend role and SQL
   statement, by joining pgpool_adm_pcp_proc_info,
   pgpool_adm_pcp_node_info and pgpool_adm_pcp_pool_status.
   <programlisting>
create function pgpool_query_info(pcp_host text, pcp_port int, pgpool_username text, password text)
returns table (username text, database text, client_host text, client_port text,
pgpool_host text, pgpool_port text, pgpool_pid text,
backend_host text, backend_port text, backend_pid text, backend_role text, statement text) as $$
select p.username, p.database, p.client_host,p.client_port,
$1 as pgpool_host, s.value as pgpool_port, p.pid as pgpool_pid,
b.host as backend_host, b.port as backend_port, p.backend_pid as backend_pid,
b.role as backend_role,
p.statement
from pcp_proc_info(host=> $1, port => $2, username => $3, password => $4) as p,
pcp_node_info(node_id=>p.backend_id::int, host => $1, port => $2,
username => $3, password => $4) as b,
pcp_pool_status(host=> $1, port => $2, username => $3, password => $4) as s
where p.connected = 1::text and p.statement != '' and
p.statement !~ 'pcp_proc_info' and p.statement !~ 'pgpool_query_info' and
s.item = 'port'
$$
language SQL;
CREATE FUNCTION

select * from pgpool_query_info('192.168.10.11', 11001, 't-ishii', 't-ishii');
 username | database |  client_host  | client_port |  pgpool_host  | pgpool_port | pgpool_pid | backend_host | backend_port | backend_pid | backend_role | statement 
----------+----------+---------------+-------------+---------------+-------------+------------+--------------+--------------+-------------+--------------+-----------
 t-ishii  | test     | 192.168.10.11 | 60542       | 192.168.10.11 | 11000       | 1356156    | localhost    | 11002        | 1356240     | Primary      | select 2;
 t-ishii  | test     | 192.168.10.11 | 43856       | 192.168.10.11 | 11000       | 1356167    | localhost    | 11003        | 1356255     | Standby      | select 1;
(2 rows)
   </programlisting>
  </para>
  <para>
   See <xref linkend="pcp-proc-info"> for more information on each
   shown data.
  </para>

 </refsect1>

</refentry>
