Cookbook recipe

Read the lock manager: pg_locks decoded

Applies to PostgreSQL 13–17 Last reviewed May 2026 Grounded in source
Estimated investigation4 min

Scenario

pg_locks is dense and cryptic. Learn to read it to understand exactly what each session holds and waits for. Diagnose it Join locks to activity for readable output: SELECT l.pid, l.locktype, l.mode, l.granted, left(a.query,50) FROM pg_locks…

Investigation Path

pg_locks is dense and cryptic. Learn to read it to understand exactly what each session holds and waits for.

Diagnose it

Join locks to activity for readable output:

SELECT l.pid, l.locktype, l.mode, l.granted, left(a.query,50)
FROM pg_locks l JOIN pg_stat_activity a USING (pid)
ORDER BY l.granted, l.pid;

Why it happens

Each row is a lock request: granted=false means a session is waiting. locktype (relation, tuple, transactionid) and mode (e.g. AccessShareLock, RowExclusiveLock, AccessExclusiveLock) tell you what kind of access is held or wanted.

This is a Pro lesson

Get every Learning Pathway and cookbook recipe — grounded in PostgreSQL source code, with diagnostics, fixes, and prevention for each topic.

Continue this lesson to learn:

  • How to fix it
  • Prevent it next time
  • Related & next steps
  • All 36 Learning Pathway lessons
  • 170+ cookbook recipes
  • Source-grounded diagnostics & fixes

Secure checkout Cancel anytime Source-grounded

Career Impact

This scenario builds production judgment and operational confidence under pressure.

Open Career Dashboard →

Keep going

Related & next steps

Was this helpful?

← All cookbook recipes