Diagnosing Live Activity with pg_stat_activity
Learn to use the pg_stat_activity view to see what every connection is doing right now, find long-running and blocked queries, and safely cancel or terminate problem sessions.
Your Window into Live Sessions
The pg_stat_activity view has one row per server connection. It is the first place to look when the database feels slow or stuck, showing what each session is doing this instant.
The Key Columns
The most useful columns are:
pid: the backend process idstate: active, idle, idle in transactionquery: the current or last SQL textwait_event: what the session is waiting on
All lessons in this course
- Using pg_stat_statements and pg_buffercache
- Logging Configuration for Analysis
- External Monitoring Tools Integration
- Diagnosing Live Activity with pg_stat_activity