Quick Answer
Lock contention detection: pg_stat_activity shows wait_event and wait_event_type. Wait event "Lock" means waiting for another session's lock. pg_locks view shows all current locks and who is waiting for what. pg_blocking_pids(pid) returns which PIDs are blocking a session. pg_stat_activity joined with pg_locks gives a complete picture of blocking chains. Long-running transactions are the most common cause.
Answer
Lock contention is detected using pg_locks, pg_stat_activity, and wait events. These tools reveal blocked queries and lock chains.
S
SugharaIQ Editorial Team
Verified Answer
This answer has been peer-reviewed by industry experts holding senior engineering roles to ensure technical accuracy and relevance for modern interview standards.