首页 > 代码库 > 查看postgre都有哪些语句执行时间长

查看postgre都有哪些语句执行时间长

查看所有postgre语句执行时间:

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 <> <IDLE> --and procpid = 17637order by lap desc;
  • procpid:进程id
  • start:进程开始时间
  • lap:经过时间
  • current_query:执行中的sql

怎样停止正在执行的sql?

优雅的方法:SELECT pg _cancel_backend(进程id);

或者用系统函数:kill -9 进程id;