pg_stat_activity
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, seepg_stat_activity_global
Table 1. pg_catalog.pg_stat_activity
column |
type |
references |
description |
|---|---|---|---|
|
oid |
database oid |
|
|
name |
database name |
|
|
integer |
process ID |
|
|
integer |
session ID |
|
|
oid |
user OID |
|
|
name |
user name |
|
|
text |
current query |
|
|
boolean |
query’s waiting status |
|
|
timestamp with time zone |
time at which the current query began execution |
|
|
timestamp with time zone |
time at which he process was started |
|
|
inet |
client’s address number |
|
|
integer |
client’s port number |
|
|
text |
the name of backend process connect to server |
|
|
timestamp with time zone |
time at which the current transaction started. Null when the process is without transaction. |
|
|
boolean |
status of waiting for resource manager. |