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__);