域名預(yù)訂/競(jìng)價(jià),好“米”不錯(cuò)過(guò)
這篇文章主要介紹了PostgreSQL查看正在執(zhí)行的任務(wù)并強(qiáng)制結(jié)束的操作方法,本文給大家介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或工作具有一定的參考借鑒價(jià)值,需要的朋友可以參考下。
查看任務(wù)sql語(yǔ)句:
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:進(jìn)程id
start:進(jìn)程開(kāi)始時(shí)間
lap:經(jīng)過(guò)時(shí)間
current_query:執(zhí)行中的sql
強(qiáng)制停止某一個(gè)任務(wù):
SELECT pg_cancel_backend(進(jìn)程id);
補(bǔ)充:
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';
文章來(lái)源:腳本之家
來(lái)源地址:https://www.jb51.net/article/204299.htm
申請(qǐng)創(chuàng)業(yè)報(bào)道,分享創(chuàng)業(yè)好點(diǎn)子。點(diǎn)擊此處,共同探討創(chuàng)業(yè)新機(jī)遇!