Summary
The pg_stat_activity view will have one row per server process, showing information related to the current activity of that process.
(Description quoted from the official PostgreSQL documentation.)
Columns
The pg_stat_activity statistics view exposes the following columns (names, types and descriptions are taken verbatim from the PostgreSQL documentation):
datidoid
OID of the database this backend is connected todatnamename
Name of the database this backend is connected topidinteger
Process ID of this backendleader_pidinteger
Process ID of the parallel group leader if this process is a parallel query worker, or process ID of the leader apply worker if this process is a parallel apply worker. NULL indicates that this process is a parallel group leader or leader apply worker, or does not participate in any parallel operation.usesysidoid
OID of the user logged into this backendusenamename
Name of the user logged into this backendapplication_nametext
Name of the application that is connected to this backendclient_addrinet
IP address of the client connected to this backend. If this field is null, it indicates either that the client is connected via a Unix socket on the server machine or that this is an internal process such as autovacuum.client_hostnametext
Host name of the connected client, as reported by a reverse DNS lookup of client_addr. This field will only be non-null for IP connections, and only when log_hostname is enabled.client_portinteger
TCP port number that the client is using for communication with this backend, or -1 if a Unix socket is used. If this field is null, it indicates that this is an internal server process.backend_starttimestamp with time zone
Time when this process was started. For client backends, this is the time the client connected to the server.xact_starttimestamp with time zone
Time when this process’ current transaction was started, or null if no transaction is active. If the current query is the first of its transaction, this column is equal to the query_start column.query_starttimestamp with time zone
Time when the currently active query was started, or if state is not active, when the last query was startedstate_changetimestamp with time zone
Time when the state was last changedwait_event_typetext
The type of event for which the backend is waiting, if any; otherwise NULL. See wait_event_table.wait_eventtext
Wait event name if backend is currently waiting, otherwise NULL. See wait_event_activity_table through wait_event_timeout_table.statetext
Current overall state of this backend. Possible values are: starting: The backend is in initial startup. Client authentication is performed during this phase. active: The backend is executing a query. idle: The backend is waiting for a new client command. idle in transaction: The backend is in a transaction, but is not currently executing a query. idle in transaction (aborted): This state is similar to idle in transaction, except one of the statements in the transaction caused an error. fastpath function call: The backend is executing a fast-path function. disabled: This state is reported if track_activities is disabled in this backend.backend_xidxid
Top-level transaction identifier of this backend, if any; see transaction_id.backend_xminxid
The current backend’s xmin horizon.query_idbigint
Identifier of this backend’s most recent query. If state is active this field shows the identifier of the currently executing query. In all other states, it shows the identifier of last query that was executed. Query identifiers are not computed by default so this field will be null unless compute_query_id parameter is enabled or a third-party module that computes query identifiers is configured.querytext
Text of this backend’s most recent query. If state is active this field shows the currently executing query. In all other states, it shows the last query that was executed. By default the query text is truncated at 1024 bytes; this value can be changed via the parameter track_activity_query_size.backend_typetext
Type of current backend. Possible types are autovacuum launcher, autovacuum worker, logical replication launcher, logical replication worker, parallel worker, background writer, client backend, checkpointer, archiver, standalone backend, startup, walreceiver, walsender, walwriter and walsummarizer. In addition, background workers registered by extensions may have additional types.
Version applicability
Present in PostgreSQL 17, 18, 19 (verified against each release’s documentation). This is a long-standing system object that also exists in earlier PostgreSQL releases.
Related & references
Reference: PostgreSQL documentation — pg_stat_activity.