활성 쿼리 및 블로킹 쿼리 조회
PostgreSQL세션명령어
SELECT pid, usename, state, wait_event_type, wait_event, pg_blocking_pids(pid) AS blocking_pids, now() - query_start AS duration, left(query, 100) AS query FROM pg_stat_activity WHERE state <> 'idle' AND pid <> pg_backend_pid() ORDER BY duration DESC;하는 일
idle이 아닌 모든 backend와 이를 블로킹하는 PID, 실행 시간을 나열한다.
사용 시점
락/블로킹 문제와 장시간 실행 쿼리를 진단하기 위해.
주의
pg_blocking_pids는 PostgreSQL 9.6+에서 사용할 수 있다. blocking_pids 배열이 비어 있지 않으면 해당 PID가 락을 잡고 있으므로 필요하면 그 PID를 cancel/terminate한다.