查看任務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:經(jīng)過時間
current_query:執(zhí)行中的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';
到此這篇關(guān)于PostgreSQL查看正在執(zhí)行的任務并強制結(jié)束的文章就介紹到這了,更多相關(guān)PostgreSQL查看正在執(zhí)行內(nèi)容請搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!