Skip to content

.tip

· one of the small things

Read wait_event before you guess why a query is slow

pg_stat_activity tells you what's running, and in the same row, what it's waiting on.

SELECT pid, now() - query_start AS age, wait_event_type, wait_event, left(query, 60)
FROM pg_stat_activity WHERE state <> 'idle' ORDER BY age DESC;

Lock means it's queued behind another session, and IO means disk. LWLock under load usually means contention on a hot buffer. Each needs a different fix, and that column saves you from applying the wrong one.

postgresqldebugging