Ref

현재 (오래) 실행 중인 쿼리 확인

WITH CTE AS
(
    SELECT
           PID
          ,NOW() - QUERY_START AS DURATION
          ,STATE
          ,USENAME
          ,APPLICATION_NAME    AS APP_NAME
          ,QUERY
    FROM pg_stat_activity
)
SELECT *
FROM CTE
WHERE STATE = 'active'
  AND DURATION > INTERVAL '1 minutes'
;

실행 중인 쿼리 중단

-- 부드럽게 중단
SELECT pg_cancel_backend(__pid__);

-- 강제 중단
SELECT pg_terminate_backend(__pid__);