亚洲激情专区-91九色丨porny丨老师-久久久久久久女国产乱让韩-国产精品午夜小视频观看

溫馨提示×

溫馨提示×

您好,登錄后才能下訂單哦!

密碼登錄×
登錄注冊×
其他方式登錄
點擊 登錄注冊 即表示同意《億速云用戶服務條款》

查找和殺掉postgresql堵塞的會話

發布時間:2020-08-17 20:06:32 來源:網絡 閱讀:1262 作者:春秋小記 欄目:數據庫

查找和殺掉postgresql堵塞的會話
1.創建視圖,可以隨時使用:
CREATE VIEW pg_blocking AS SELECT
blocked_locks.pid AS blocked_pid,
blocked_activity.usename AS blocked_user,
blocking_locks.pid AS blocking_pid,
blocking_activity.usename AS blocking_user,
blocked_activity. QUERY AS blocked_statement,
blocking_activity. QUERY AS current_statement_in_blocking_process
FROM
pg_catalog.pg_locks blocked_locks
JOIN pg_catalog.pg_stat_activity blocked_activity ON blocked_activity.pid = blocked_locks.pid
JOIN pg_catalog.pg_locks blocking_locks ON blocking_locks.locktype = blocked_locks.locktype
AND blocking_locks. DATABASE IS NOT DISTINCT
FROM
blocked_locks. DATABASE
AND blocking_locks.relation IS NOT DISTINCT
FROM
blocked_locks.relation
AND blocking_locks.page IS NOT DISTINCT
FROM
blocked_locks.page
AND blocking_locks.tuple IS NOT DISTINCT
FROM
blocked_locks.tuple
AND blocking_locks.virtualxid IS NOT DISTINCT
FROM
blocked_locks.virtualxid
AND blocking_locks.transactionid IS NOT DISTINCT
FROM
blocked_locks.transactionid
AND blocking_locks.classid IS NOT DISTINCT
FROM
blocked_locks.classid
AND blocking_locks.objid IS NOT DISTINCT
FROM
blocked_locks.objid
AND blocking_locks.objsubid IS NOT DISTINCT
FROM
blocked_locks.objsubid
AND blocking_locks.pid != blocked_locks.pid
JOIN pg_catalog.pg_stat_activity blocking_activity ON blocking_activity.pid = blocking_locks.pid
WHERE
NOT blocked_locks.GRANTED;
查詢創建的視圖查詢堵塞:
select  * from  pg_blocking;
2.殺掉查出的阻塞會話:
kill有兩種方式,第一種是:
SELECT pg_cancel_backend(PID);  ###取消一個正在執行的SQL;
第二種是:
SELECT pg_terminate_backend(PID);  ###終止一個后臺服務進程,同時釋放此后臺服務進程的資源。

這兩個函數的區別是:pg_cancel_backend()函數實際上是給正在執行的SQL任務配置一個取消標志,正在執行的任務是在合適的時候檢測到此標志后主動退出;但如果這個任務沒有主動檢測到這個標志,則該任務就無法正常退出,這時需要使用pg_terminate_backend()命令在終止SQL的執行。
通常是先查詢pg_stat_activity,試圖找出長時間運行的SQL,然后進行終止,也可以批量終止回話:
SELECT  'SELECT pg_terminate_backend('||blocking_pid||');' from pg_blocking;

向AI問一下細節

免責聲明:本站發布的內容(圖片、視頻和文字)以原創、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。

AI

南宁市| 曲麻莱县| 富宁县| 故城县| 栖霞市| 江安县| 张家川| 黄浦区| 来安县| 大石桥市| 东乌珠穆沁旗| 武汉市| 宁武县| 合水县| 连江县| 竹北市| 韶关市| 交口县| 英德市| 辛集市| 松滋市| 安西县| 大庆市| 陇川县| 连山| 沁源县| 邵东县| 都兰县| 普兰店市| 临武县| 胶南市| 新宁县| 宝兴县| 海宁市| 义乌市| 四子王旗| 左云县| 湾仔区| 从化市| 公主岭市| 肇东市|