PG_STAT_ACTIVITY
PG_STAT_ACTIVITY shows information about the current user's queries.
Table 1 PG_STAT_ACTIVITY columns
OID of the database that the user session connects to in the backend | ||
Name of the database that the user session connects to in the backend | ||
IP address of the client connected to the backend. If this column is null, it indicates either the client is connected via a Unix socket on the server or this is an internal process, such as autovacuum. | ||
Host name of the connected client, as reported by a reverse DNS lookup of client_addr. This column will be non-null only for IP connections and only when log_hostname is enabled. | ||
TCP port number that the client uses for communication with this backend (-1 if a Unix socket is used) | ||
Time when this process was started, that is, when the client connected to the server | ||
Time when current transaction was started (null if no transaction is active) If the current query is the first of its transaction, the value of this column is the same as that of the query_start column. | ||
Time when the currently active query was started, or if state is not active, when the last query was started | ||
Whether the backend is currently waiting on a lock. If yes, the value is true. | ||
Overall status of this backend. The value must be one of the following:
NOTE: Common users can view their own session status only. The state information of other accounts is empty. For example, after user judy is connected to the database, the state information of user joe and the initial user omm in pg_stat_activity is empty. SELECT datname, usename, usesysid, state,pid FROM pg_stat_activity; datname | usename | usesysid | state | pid ----------+---------+----------+--------+----------------- postgres | omm | 10 | | 139968752121616 postgres | omm | 10 | | 139968903116560 db_tpcc | judy | 16398 | active | 139968391403280 postgres | omm | 10 | | 139968643069712 postgres | omm | 10 | | 139968680818448 postgres | joe | 16390 | | 139968563377936 (6 rows) | ||
Text of this backend's most recent query. If state is active, this column shows the ongoing query. In all other states, it shows the last query that was executed. | ||
A string in JSON format recording the driver type, driver version, driver deployment path, and process owner of the connected database. For details, see connection_info. |