Updated on 2024-09-02 GMT+08:00

PG_STAT_ACTIVITY

PG_STAT_ACTIVITY displays information about the current user's queries. If you have the rights of an administrator or the preset role, you can view all information about user queries.

Table 1 PG_STAT_ACTIVITY columns

Name

Type

Description

datid

oid

OID of the database that the user session connects to in the backend

datname

name

Name of the database that the user session connects to in the backend

pid

bigint

Backend thread ID

lwtid

integer

Lightweight thread ID

usesysid

oid

OID of the user logging in to the backend

usename

name

OID of the user logging in to the backend

application_name

text

Name of the application connected to the backend

client_addr

inet

IP address of the client connected to the backend If this column 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 column will only be non-null for IP connections, and only when log_hostname is enabled.

client_port

integer

TCP port number that the client uses for communication with this backend, or -1 if a Unix socket is used

backend_start

timestamp with time zone

Startup time of the backend process, that is, the time when the client connects to the server.

xact_start

timestamp with time zone

Time when the 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 for the last status change

waiting

boolean

The value is t if the backend is waiting for a lock or node. Otherwise, the value is f.

enqueue

text

Queuing status of a statement. Its value can be:
  • waiting in global queue: The statement is queuing in the global concurrent queue. The number of concurrent statements exceeds the value of max_active_statements configured for a single CN.
  • waiting in respool queue: The statement is queuing in the resource pool and the concurrency of simple jobs is limited. The main reason is that the concurrency of simple jobs exceeds the upper limit max_dop of the fast track.
  • waiting in ccn queue: The job is in the CCN queue, which may be global memory queuing, slow lane memory queuing, or concurrent queuing. The scenarios are:
    1. The available global memory exceeds the upper limit, the job is queuing in the global memory queue.
    2. Concurrent requests on the slow lane in the resource pool exceed the upper limit, which is specified by active_statements.
    3. The slow lane memory of the resource pool exceeds the upper limit, that is, the estimated memory of concurrent jobs in the resource pool exceeds the upper limit specified by mem_percent.
  • Empty or no waiting queue: The statement is running.

state

text

Current overall state of this backend. Its value can be:

  • active: The backend is executing queries.
  • idle: The backend is waiting for new client commands.
  • idle in transaction: The backend is in a transaction, but there is no statement being executed in the transaction.
  • idle in transaction (aborted): The backend is in a transaction, but there are statements failed in the transaction.
  • fastpath function call: The backend is executing a fast-path function.
  • disabled: This state is reported if track_activities is disabled in this backend.
NOTE:

Common users can view only their own session status. The state information of other accounts is empty.

resource_pool

name

Resource pool used by the user

stmt_type

text

Statement type

query_id

bigint

ID of a query

query

text

Text of the most recent query in this backend If state is active, this column shows the running query. In all other states, it shows the last query that was executed.

connection_info

text

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)