track_activities

A system parameter determining whether to collect information about queries

track_activities is a configuration parameter determining whether information about a session's currently executing command is collected.

track_activities was added in PostgreSQL 8.3.

Default value

The default value for track_activities is: on.

Usage

track_activities collects the following information about a session's query:

  • query text
  • transaction start time
  • query start time
  • state change
  • query ID (PostgreSQL 14 and later)

Note that the length of the tracked query text is determined by track_activity_query_size.

The query ID will only be displayed if compute_query_id is enabled.

The tracked query information is only available to the session's owner and superusers.

Change history

Examples

Comparision of pg_stat_activity records with track_activities disabled then enabled:

postgres=# SHOW track_activities;
 track_activities
------------------
 off
(1 row)

postgres=# SELECT * FROM pg_stat_activity WHERE pid=646117;
-[ RECORD 1 ]----+------------------------------
datid            | 5
datname          | postgres
pid              | 646117
leader_pid       | 
usesysid         | 10
usename          | postgres
application_name | psql
client_addr      | ::1
client_hostname  | 
client_port      | 19858
backend_start    | 2022-04-20 14:03:01.309361+01
xact_start       | 
query_start      | 
state_change     | 
wait_event_type  | Timeout
wait_event       | PgSleep
state            | disabled
backend_xid      | 
backend_xmin     | 736
query_id         | 
query            | 
backend_type     | client backend

postgres=# SHOW track_activities;
 track_activities
------------------
 on
(1 row)

postgres=# SELECT * FROM pg_stat_activity WHERE pid=646117;
-[ RECORD 1 ]----+------------------------------
datid            | 5
datname          | postgres
pid              | 646117
leader_pid       | 
usesysid         | 10
usename          | postgres
application_name | psql
client_addr      | ::1
client_hostname  | 
client_port      | 19858
backend_start    | 2022-04-20 14:03:01.309361+01
xact_start       | 2022-04-20 14:19:56.183189+01
query_start      | 2022-04-20 14:19:56.183189+01
state_change     | 2022-04-20 14:19:56.18319+01
wait_event_type  | Timeout
wait_event       | PgSleep
state            | active
backend_xid      | 
backend_xmin     | 736
query_id         | 7672947883565430115
query            | SELECT pg_sleep(180);
backend_type     | client backend

Categories

GUC configuration item, Monitoring, Server statistics

See also

pg_stat_activity, track_activity_query_size