跳转到主要内容
← 目录图谱 / pg_stat_activity

STATISTICS VIEW · 统计视图

pg_stat_activity

The pg_stat_activity view will have one row per server process, showing information related to the current activity of that process. Here are examples of how wait events can be viewed:

首次收录 PG 9.0最近收录 PG 19当前字段 22

已与 PostgreSQL 18.6 实例逐字段核对 · 原始实测记录 ↗

字段结构 PostgreSQL 18

pg_stat_activity
字段 / COLUMN类型 / TYPE说明 / DESCRIPTION
datid oid OID of the database this backend is connected to
datname name Name of the database this backend is connected to
pid integer Process ID of this backend
leader_pid integer 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.
usesysid 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. If this field is null, it indicates that this is an internal server process.
backend_start timestamp with time zone Time when this process was started. For client backends, this is the time the client connected to the server.
xact_start timestamp 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_start timestamp with time zone Time when the currently active query was started, or if state is not active, when the last query was started
state_change timestamp with time zone Time when the state was last changed
wait_event_type text The type of event for which the backend is waiting, if any; otherwise NULL. See Table 27.4.
wait_event text Wait event name if backend is currently waiting, otherwise NULL. See Table 27.5 through Table 27.13.
state text Current overall state of this backend. Possible values are:
backend_xid xid Top-level transaction identifier of this backend, if any; see Section 67.1.
backend_xmin xid The current backend's xmin horizon.
query_id bigint 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.
query text 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_type text 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.

标记“隐式列”的字段不包含在 SELECT * 中;部分早期统计视图由同版本源码补全,额外来源会显示在字段说明中。

字段演化矩阵

悬停查看字段类型
存在新增 / 类型或属性变化移除
字段 / COLUMN9.09.19.29.39.49.59.610111213141516171819
datid
datname
procpid
usesysid
usename
application_name
client_addr
client_port
backend_start
xact_start
query_start
waiting
current_query
client_hostname
pid
state_change
state
query
backend_xid
backend_xmin
wait_event_type
wait_event
backend_type
leader_pid
query_id

9.0 是收录基线;基线中已存在的字段不标记为新增。矩阵按字段名称对齐,重命名显示为旧字段移除与新字段新增。

演化时间线

相邻大版本的变化

PostgreSQL 18 ← 17

1 处字段说明更新

PostgreSQL 17 ← 16

4 处字段说明更新目录说明更新

PostgreSQL 16 ← 15

3 处字段说明更新

PostgreSQL 14 ← 13

+ query_id3 处字段说明更新

PostgreSQL 13 ← 12

+ leader_pid4 处字段说明更新目录说明更新

PostgreSQL 12 ← 11

1 处字段说明更新目录说明更新

PostgreSQL 11 ← 10

1 处字段说明更新

PostgreSQL 10 ← 9.6

+ backend_type4 处字段说明更新目录说明更新

PostgreSQL 9.6 ← 9.5

+ wait_event_type+ wait_event− waiting目录说明更新

PostgreSQL 9.5 ← 9.4

目录说明更新

PostgreSQL 9.4 ← 9.3

+ backend_xid+ backend_xmin目录说明更新

PostgreSQL 9.2 ← 9.1

+ pid+ state_change+ state+ query− procpid− current_query2 处字段说明更新目录说明更新

PostgreSQL 9.1 ← 9.0

+ client_hostname目录说明更新

比较任意两个版本

选择两个版本,查看字段的新增、移除与类型变化。交互比较需要 JavaScript;演化时间线可直接阅读。