PostgreSQL

Lock contention visible in pg_locks indicates waiting processes

warning
Resource ContentionUpdated Feb 26, 2026
Technologies:
How to detect:

When granted=false in pg_locks, the process is waiting to acquire a lock because at least one other process holds or is waiting for a conflicting lock mode on the same object. A single process can wait for at most one lock at a time.

Recommended action:

Query pg_locks joined with pg_stat_activity to identify waiting processes: SELECT * FROM pg_locks pl LEFT JOIN pg_stat_activity psa ON pl.pid = psa.pid WHERE pl.granted = false. Use pg_blocking_pids() function to identify which process(es) are blocking the waiting process. Investigate the blocking queries and consider terminating long-running transactions if appropriate.