pg_stat_get_backend_activity()

A function reporting a backend's most recent query

pg_stat_get_backend_activity() is a system function reporting the text of a backend's most recent query.

pg_stat_get_backend_activity() was added in PostgreSQL 7.2.

Usage

pg_stat_get_backend_activity ( integer ) → text

The backend is specified by a backend ID number reported by pg_stat_get_backend_idset(); see below for an execution example.

The value returned by pg_stat_get_backend_activity_start() corresponds to the column query (PostgreSQL 9.1 and earlier: current_query) in pg_stat_activity.

The following related functions are also available:

Change history

Examples

Basic usage example for pg_stat_get_backend_activity_start():

postgres=# SELECT pg_stat_get_backend_pid(s.backendid) AS pid,
                  pg_stat_get_backend_activity(s.backendid) AS query
             FROM (SELECT pg_stat_get_backend_idset() AS backendid) AS s;
   pid   |                              query                           
---------+-----------------------------------------------------------------
 1451980 | 
 1451982 | 
 2072322 | SELECT pg_stat_get_backend_pid(s.backendid) AS pid,            +
         |        pg_stat_get_backend_activity(s.backendid) AS query_start+
         |   FROM (SELECT pg_stat_get_backend_idset() AS backendid) AS s;
 1764534 | SELECT pg_stat_get_backend_pid(s.backendid) AS pid             +
         |   FROM (SELECT pg_stat_get_backend_idset() AS backendid) AS s;
 1451978 | 
 1451977 | 
 1451979 | 
(7 rows)

Categories

System function

See also

pg_stat_activity