Parameter · Statistics / Cumulative Query and Index Statistics
track_activities
Collects information about executing commands. Enables the collection of information on the currently executing command of each session, along with the time at which that command began execution.
- Default:
on - Type: bool
- Applies: Session (superuser)
In plain words
Each session continuously publishes what it is doing: the current query, whether it is active or idle, and since when. That is what you see in pg_stat_activity. Turning this off hides that information, which leaves you blind when something is slow or stuck.
The cost is tiny, so keep it on.
For DBAs and operators
With it on, a session updates its shared-memory entry at every statement start/end: state, query, query_start, xact_start, state_change, query_id. Verified on 18.6 by connecting with PGOPTIONS="-c track_activities=off" and running pg_sleep(3):
pid | state | query | query_id | wait_event
------+----------+-------+----------+------------
2012 | disabled | | | PgSleepThe row still exists (pid, user, wait_event, backend_start) but the state is disabled and the query is empty. It can be changed per session by superusers (or roles granted SET on it), so one session can hide itself.
Visibility: only superusers, members of pg_read_all_stats, and the session's own role see other users' query text; everyone else sees <insufficient privilege>. That is why keeping it on is not a security risk. Query text length is limited by track_activity_query_size.
How to change it
A superuser (or a role granted SET) can change it per session with SET.
See it in context
Related parameters
track_activity_query_size track_counts compute_query_id update_process_title