查询正在获取锁的sql
SELECT locker.pid,
pc.relname,
locker.mode,
locker_act.application_name,
least(query_start,xact_start) start_time,
locker_act.state,
CASE
WHEN granted='f' THEN
'wait_lock'
WHEN granted='t' THEN
'get_lock'
END lock_satus,current_timestamp - least(query_start,xact_start) AS runtime,
locker_act.query
FROM pg_locks locker,pg_stat_activity locker_act, pg_class pc
WHERE locker.pid=locker_act.pid
AND NOT locker.pid=pg_backend_pid()
AND application_name<>'pg_statsinfod'
AND locker.relation = pc.oid
AND pc.reltype<>0 --and pc.relname='t_apply_gather_plan_ref'
ORDER BY runtime desc;
查询正在执行的sql
SELECT *
FROM pg_stat_activity
WHERE datname = 'scm3'
AND STATE = 'active'
AND waiting = TRUE
AND now() - query_start > '5 sec' :: INTERVAL;
停止正在执行的sql
SELECT pg_cancel_backend(进程id);
网友评论