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
怎樣中止正在執行的sql
SELECT pg_cancel_backend(進程id);
或者用系統函數
kill -9 進程id;sql