PostgreSQL中函数pg_blocking_pids的作用是什么

发布时间:2021-11-08 16:47:15 作者:iii
来源:亿速云 阅读:326

本篇内容介绍了“PostgreSQL中函数pg_blocking_pids的作用是什么”的有关知识,在实际案例的操作过程中,不少人都会遇到这样的困境,接下来就让小编带领大家学习一下如何处理这些情况吧!希望大家仔细阅读,能够学有所成!

函数pg_blocking_pids用于获取哪些进程(输出参数)阻塞了某个进程(输入参数).

我们在执行某些操作时,console可能会挂起没有输出,这时候你没有办法判断是因为执行很慢还是因为被阻塞了,通过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=#

通过查询可发现阻塞pid = 1628的进程1541.这时候可以查询pg_locks和进程活动信息获取更详细的信息

[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

进程活动信息

[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中函数pg_blocking_pids的作用是什么”的内容就介绍到这里了,感谢大家的阅读。如果想了解更多行业相关的知识可以关注亿速云网站,小编将为大家输出更多高质量的实用文章!

推荐阅读:
  1. PostgreSQL源码中NOT IN的作用是什么
  2. PostgreSQL的dump函数有什么作用

免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。

postgresql

上一篇:PostgreSQL的OID类型是什么

下一篇:PostgreSQL的日志文件参数及注意事项有哪些

相关阅读

您好,登录后才能下订单哦!

密码登录
登录注册
其他方式登录
点击 登录注册 即表示同意《亿速云用户服务条款》