Postgresql 查阻塞源

  • 先确定当前有哪些pid被阻塞
SELECT pid,waiting,query_start,query FROM pg_stat_activity where waiting

返回

  • 再根据当前的pid查阻塞源资料
select * from (SELECT 
 procpid, 
 start, 
 now() - start AS lap, 
 current_query 
 FROM 
 (SELECT 
 backendid, 
 pg_stat_get_backend_pid(S.backendid) AS procpid, 
 pg_stat_get_backend_activity_start(S.backendid) AS start, 
 pg_stat_get_backend_activity(S.backendid) AS current_query 
 FROM 
 (SELECT pg_stat_get_backend_idset() AS backendid) AS S 
 ) AS S 
 WHERE 
 current_query <> '' 
 ORDER BY 
 lap DESC) b where b.procpid=(select pid
   from (select a.locktype,
                a.transactionid,
                a.virtualtransaction,
                b.pid,
                a.mode,
                a.granted
           from pg_locks a, pg_locks b
          where a.transactionid = b.transactionid
            and a.transactionid is not null
            and a.granted = 'f') b
  where b.pid != 23512);

 

经确认后, 可以用select pg_terminate_backend(23495)来粗暴杀死这个阻塞源.

 

你可能感兴趣的:(postgreSQL,语言设计)