1. Home
  2. Knowledge Base
  3. PostgreSQL
  4. Understanding PostgreSQL pg_stat_activity
  1. Home
  2. Knowledge Base
  3. PostgreSQL DBA
  4. Understanding PostgreSQL pg_stat_activity
  1. Home
  2. Knowledge Base
  3. PostgreSQL Troubleshooting
  4. Understanding PostgreSQL pg_stat_activity

Understanding PostgreSQL pg_stat_activity

The pg_stat_activity view in PostgreSQL provides information about the current activity of each server process. The view returns one row for each server process, showing the current state of that process.

The following table describes the columns of pg_stat_activity view in PostgreSQL:

Column NameDescription
datidOID of the database that this backend is connected to
datnameName of the database that this backend is connected to
pidProcess ID of this backend
usesysidOID of the user that owns this backend
usenameName of the user that owns this backend
application_nameName of the application that is connected to this backend
client_addrIP address of the client connected to this backend
client_hostnameHost name of the client connected to this backend
client_portTCP port number that the client is using for communication with this backend
backend_startTime when this process was started, i.e., when the client connected to the database
xact_startTime when this process started the current transaction, if any
query_startTime when the currently executing query was started, if any
state_changeTime when the state of this process last changed
waitingWhether this process is currently waiting for a lock
stateCurrent state of this backend
backend_xidTransaction ID of the current transaction, if any
backend_xminMinimal transaction ID that this backend will accept for queries
queryText of this backend’s most recent query, if any

The pg_stat_activity view can be used for troubleshooting PostgreSQL performance by identifying long-running queries, tracking connections and their associated states, and checking for blocked queries. For example, the view can be used to find queries that have been running for a long time, queries that are waiting for locks, and queries that are blocking other queries.

Was this article helpful?

Related Articles

Need Support?

Can't find the answer you're looking for?
Contact Support