# pg_stat_activity
When using the statistics to monitor current activity, it is important to realize that the information does not update instantaneously. Each individual server process transmits new block and row access counts to the collector just before going idle; so a query or transaction still in progress does not affect the displayed totals. Also, the collector itself emits a new report at most once per `PGSTAT_STAT_INTERVAL` milliseconds (500 unless altered while building the server). So the displayed information lags behind actual activity. However, current-query information collected by `stats_command_string` is always up-to-date.
Another important point is that when a server process is asked to display any of these statistics, it first fetches the most recent report emitted by the collector process and then continues to use this snapshot for all statistical views and functions until the end of its current transaction. So the statistics will appear not to change as long as you continue the current transaction. Similarly, information about the current queries of all processes is collected when any such information is first requested within a transaction, and the same information will be displayed throughout the transaction. This is a feature, not a bug, because it allows you to perform several queries on the statistics and correlate the results without worrying that the numbers are changing underneath you. But if you want to see new results with each query, be sure to do the queries outside any transaction block.
`pg_stat_activity` can provide information about the status of query that run on the main node.If you want to see the global status of query, see[pg_stat_activity_global](./pg_stat_activity_global.md)
Table 1. `pg_catalog.pg_stat_activity`
| column | type | references | description |
| :----------------- | :----------------------- | :--------- | :----------------------------------------------------------- |
| `datid` | oid | pg_database.oid | Database OID |
| `datname` | name | | Database name |
| `pid` | integer | | Thread ID of this backend |
| `sess_id` | integer | | Session ID |
| `usesysid` | oid | pg_authid.oid | OID of the user logged into this backend |
| `usename` | name | | Name of the user logged into this backend |
| `application_name` | text | | Name of the application that is connected to this backend |
| `client_addr` | inet | | 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_hostname` | text | | 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_port` | integer | | TCP port number that the client is using for communication with this backend, or -1 if a Unix socket is used |
| `backend_start` | timestamp with time zone | | Time backend process was started |
| `xact_start` | timestamp with time zone | | Transaction start time |
| `query_start` | timestamp with time zone | | Time query began execution |
| `state_change` | timestamp with time zone | | Time when the state was last changed |
| `wait_event_type` | text | | Type of event for which the backend is waiting |
| `wait_event` | text | | Wait event name if backend is currently waiting |
| `state` | text | | Current overall state of this backend. Possible values are:
- active: The backend is running 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 running 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 running a fast-path function.
- disabled: This state is reported if track_activities is deactivated in this backend. |
| `backend_xid` | xid | | The top-level transaction identifier of this backend, if any. |
| `backend_xmin` | xid | | The current backend's xmin horizon. |
| `query` | text | | Text of this backend's most recent query. If state is active this field shows the currently running query. In all other states, it shows the last query that was run. |
| `backend_type` | text | | The type of the current backend. |
| `rsgid` | integer | | Resource group OID or 0. |
| `rsgname` | text | | Resource group name or unknown. |