SQL Queries - Common SQL Queries - How to check the postgres sessions that are blocking another session
Purpose of Query
The purpose of this query is to find the postgres sessions that are blocking another postgres session.
Applicable CAST Version
| Release | Yes/No |
|---|---|
| 8.3.x | ✅ |
Applicable RDBMS
| RDBMS | Yes/No |
|---|---|
| Oracle Server | ❓ |
| Microsoft SQL Server | ❓ |
| CSS4 | ✅ |
| CSS3 | ✅ |
| CSS2 | ✅ |
Query for CSS
select pid,
usename,
pg_blocking_pids(pid) as blocked_by,
query as blocked_query
from pg_stat_activity
where cardinality(pg_blocking_pids(pid)) > 0;
Query result example

Query result interpretation
The query will determine if there are any other postgres sessions blocking the current postgres session.
Notes/comments
Related Pages