PostgreSQL查看正在执行的任务并强制结束的操作方法
程序员文章站
2023-08-19 10:33:09
查看任务sql语句:select procpid, start, now() - start as lap, current_query from (select back...
查看任务sql语句:
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>' order by lap desc;
其中
procpid:进程id
start:进程开始时间
lap:经过时间
current_query:执行中的sql
强制停止某一个任务:
select pg_cancel_backend(进程id);
补充:
select pid, datname as db, query_start as start, now() - query_start as lap, query from pg_stat_activity where state <> 'idle' and query not like '%pg_stat_activity%' and (now() - query_start) > interval '10 seconds';
到此这篇关于postgresql查看正在执行的任务并强制结束的文章就介绍到这了,更多相关postgresql查看正在执行内容请搜索以前的文章或继续浏览下面的相关文章希望大家以后多多支持!