View locks and blocked queries in PostgreSQL
Use pg_blocking_pids to identify the sessions preventing a query from acquiring a lock.
Run this snapshot query in the affected database:
SELECT pid, usename, state, wait_event_type, wait_event, pg_blocking_pids(pid) AS blocker_pids, query_start, xact_start, queryFROM pg_stat_activityWHERE datname = current_database() AND cardinality(pg_blocking_pids(pid)) > 0ORDER BY query_start;Each row is a blocked session; blocker_pids lists its blockers.
A blocker can be idle inside an open transaction or ahead in the lock queue.
See PostgreSQL’s blocker function reference.
To inspect individual lock requests:
SELECT l.pid, l.locktype, l.mode, l.grantedFROM pg_locks AS lJOIN pg_stat_activity AS a ON a.pid = l.pidWHERE a.datname = current_database()ORDER BY l.granted, l.pid;granted = false identifies a request still waiting for its lock.
View locks and blocked queries in PostgreSQL with TableAI
Section titled “View locks and blocked queries in PostgreSQL with TableAI”- Open Admin › Locks.
- Select Waiting only to focus on waiting requests.
- Inspect the waiting session’s PID, lock mode, and query.
- Run the blocker query above to investigate the transaction holding up the work.

Ask the transaction owner to finish or roll back the blocking work. If intervention is necessary, follow cancel a query or terminate a session. That page covers target checks, confirmation, and termination risks.
Required privileges
Section titled “Required privileges”No extension is required.
Full activity details for other users can require pg_read_all_stats or superuser access.
Permission to read activity is separate from permission to end a session.
Related
Section titled “Related”- PostgreSQL overview.
- Connections and locks for the Admin workflow.
- Deadlock detected for a deadlock PostgreSQL has already resolved.
- Slow or timed out for other causes of waiting.
- Admin data unavailable for missing statistics access.