ccodes.net
专注资源分享

PostgreSQL查看正在执行的任务并强制结束的操作方法

 

这篇文章主要介绍了PostgreSQL查看正在执行的任务并强制结束的操作方法,本文给大家介绍的非常详细,对大家的学习或工作具有一定的参考借鉴价值,需要的朋友可以参考下。查看任务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:进程idstart:进程开始时间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’;文章

'); })();