pg_stat_activity

The view pg_stat_activity shows one row per server process with details about the associated user session and query. The columns that report data on the current query are available unless the parameter stats_command_string has been turned off. Furthermore, these columns are only visible if the user examining the view is a superuser or the same as the user owning the process being reported on.

The maximum length of the query text string stored in the column current_query can be controlled with the server configuration parameter pgstat_track_activity_query_size.

columntypereferencesdescription
datidoidpg_database.oidDatabase OID
datnamename Database name
procpidinteger Process ID of the server process
sess_idinteger Session ID
usesysidoidpg_authid.oidRole OID
usenamename Role name
current_querytext Current query that process is running
waitingboolean True if waiting on a lock, false if not waiting
query_starttimestamptz Time query began execution
backend_starttimestamptz Time backend process was started
client_addrinet Client address
client_portinteger Client port
application_nametext Client application name
xact_starttimestamptz Transaction start time
waiting_reasontext Reason the server process is waiting. The value can be:lock, replication, or resgroup
rsgidoidpg_resgroup.oidResource group OID or 0
See Note.
rsgnametextpg_resgroup.rsgnameResource group name or unknown.
See Note.
rsgqueuedurationinterval For a queued query, the total time the query has been queued.

Note: When resource groups are enabled. Only query dispatcher (QD) processes will have a rsgid and rsgname. Other server processes such as a query executer (QE) process or session connection processes will have a rsgid value of 0 and a rsgname value of unknown. QE processes are managed by the same resource group as the dispatching QD process.

Parent topic: System Catalogs Definitions