您好,登錄后才能下訂單哦!
本篇內(nèi)容介紹了“PostgreSQL中函數(shù)pg_blocking_pids的作用是什么”的有關(guān)知識(shí),在實(shí)際案例的操作過程中,不少人都會(huì)遇到這樣的困境,接下來就讓小編帶領(lǐng)大家學(xué)習(xí)一下如何處理這些情況吧!希望大家仔細(xì)閱讀,能夠?qū)W有所成!
函數(shù)pg_blocking_pids用于獲取哪些進(jìn)程(輸出參數(shù))阻塞了某個(gè)進(jìn)程(輸入?yún)?shù)).
我們?cè)趫?zhí)行某些操作時(shí),console可能會(huì)掛起沒有輸出,這時(shí)候你沒有辦法判斷是因?yàn)閳?zhí)行很慢還是因?yàn)楸蛔枞?通過pg_blocking_pids可以判斷是否存在阻塞.
----------- session 1 [local]:5432 pg12@testdb=# begin; BEGIN Time: 2.877 ms [local]:5432 pg12@testdb=#* delete from tbl where id = 1; DELETE 1 Time: 1.113 ms ----------- session 2 [local]:5432 pg12@testdb=# begin; BEGIN Time: 1.700 ms [local]:5432 pg12@testdb=#* delete from tbl where id = 1; ----------- session 3 [local]:5432 pg12@testdb=# select * from pg_blocking_pids(1628); pg_blocking_pids ------------------ {1541} (1 row) Time: 1.838 ms [local]:5432 pg12@testdb=#
通過查詢可發(fā)現(xiàn)阻塞pid = 1628的進(jìn)程1541.這時(shí)候可以查詢pg_locks和進(jìn)程活動(dòng)信息獲取更詳細(xì)的信息
[local]:5432 pg12@testdb=# select pid,locktype,relation::regclass,mode,page,tuple,virtualxid,transactionid,virtualtransaction,granted,fastpath from pg_locks where relation='tbl'::regclass; -[ RECORD 1 ]------+-------------------- pid | 1628 locktype | relation relation | tbl mode | RowExclusiveLock page | tuple | virtualxid | transactionid | virtualtransaction | 5/27 granted | t fastpath | t -[ RECORD 2 ]------+-------------------- pid | 1541 locktype | relation relation | tbl mode | RowExclusiveLock page | tuple | virtualxid | transactionid | virtualtransaction | 3/123 granted | t fastpath | t -[ RECORD 3 ]------+-------------------- pid | 1628 locktype | tuple relation | tbl mode | AccessExclusiveLock page | 0 tuple | 1 virtualxid | transactionid | virtualtransaction | 5/27 granted | t fastpath | f Time: 4.863 ms
進(jìn)程活動(dòng)信息
[local]:5432 pg12@testdb=# select * from pg_stat_activity where pid = 1541; -[ RECORD 1 ]----+------------------------------ datid | 16384 datname | testdb pid | 1541 usesysid | 10 usename | pg12 application_name | psql client_addr | client_hostname | client_port | -1 backend_start | 2019-08-14 10:46:54.422873+08 xact_start | 2019-08-14 12:06:14.357368+08 query_start | 2019-08-14 12:06:16.982161+08 state_change | 2019-08-14 12:06:16.983058+08 wait_event_type | Client wait_event | ClientRead state | idle in transaction backend_xid | 625 backend_xmin | query | delete from tbl where id = 1; backend_type | client backend Time: 8.979 ms
“PostgreSQL中函數(shù)pg_blocking_pids的作用是什么”的內(nèi)容就介紹到這里了,感謝大家的閱讀。如果想了解更多行業(yè)相關(guān)的知識(shí)可以關(guān)注億速云網(wǎng)站,小編將為大家輸出更多高質(zhì)量的實(shí)用文章!
免責(zé)聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如果涉及侵權(quán)請(qǐng)聯(lián)系站長(zhǎng)郵箱:is@yisu.com進(jìn)行舉報(bào),并提供相關(guān)證據(jù),一經(jīng)查實(shí),將立刻刪除涉嫌侵權(quán)內(nèi)容。