Read wait_event before you guess why a query is slow
pg_stat_activity tells you what is running and, in the same row, what it is 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 is queued behind another session. IO means disk. LWLock under load usually means contention on a hot buffer. Each is a different fix, and the column saves you from applying the wrong one.
postgresqldebugging