Advertisement
Pandaaaa906

PG查询被阻塞SQL

Apr 26th, 2023
1,478
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. with blocked as (
  2.     select pid,
  3.                  usename,
  4.                  client_addr,
  5.                  application_name,
  6.                  pg_blocking_pids(pid) as blocked_by,
  7.                  query as blocked_query
  8.     from pg_stat_activity
  9.     where cardinality(pg_blocking_pids(pid)) > 0
  10. ), cteBlockingHierarchy as (
  11.  
  12. SELECT
  13. all_query.pid,
  14. all_query.usename,
  15. all_query.client_addr,
  16. all_query.application_name,
  17. pg_blocking_pids(all_query.pid) as blocked_by,
  18. all_query.query as blocked_query
  19. from pg_stat_activity all_query
  20. RIGHT JOIN blocked
  21. on all_query.pid = any(blocked.blocked_by)
  22.  
  23. union
  24.  
  25. SELECT * from blocked
  26. )
  27.  
  28. SELECT * from cteBlockingHierarchy;
  29.  
  30.  
  31. -- SELECT pg_terminate_backend(20190);
  32. -- select pg_cancel_backend(220464);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement