在交易中获取TransActionID
我正在尝试从pg_locks
表中获取TransActionId
当Aquired Postgres Advisory Lock in Dressaction内部表,但它始终是null
。我想确保锁定的Aquired Witin交易。有办法做到吗?
BEGIN TRANSACTION;
SELECT pg_try_advisory_xact_lock(4);
SELECT transactionid
FROM pg_locks
WHERE locktype = 'advisory'
AND objid = 4;
Postgres容器:Postgres:13.4-Alpine
I'm trying to get transactionid
from pg_locks
table when aquired Postgres advisory lock within transaction, but it's always NULL
. I want to be sure that lock aquired witin transaction. Is there is a way to do it?
BEGIN TRANSACTION;
SELECT pg_try_advisory_xact_lock(4);
SELECT transactionid
FROM pg_locks
WHERE locktype = 'advisory'
AND objid = 4;
Postgres container: postgres:13.4-alpine
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
当您获得锁定时,交易尚未持有永久ID,您可以看到:
锁定交易ID列表中没有锁定。
从文档:
您可以尝试通过PID搜索所需的锁:
When you get a lock, your transaction is not yet holding a permanent id, you can see this:
There is no lock on hold in the list of locks transaction id.
From the doc:
You can try to search for the locks you need by pid:
doc on
pg_locks
SADE :换句话说,
,
pg_locks.transactionId
在locktype ='TransActionId'
时填充在当时。检查获取锁定的正常方法是测试pg_try_advisory_xact_lock
的返回值。要在查找
pg_locks
的事实之后进行测试,您可以使用当前后端获得的事实:The doc on
pg_locks
says:In other words,
pg_locks.transactionid
is filled in whenlocktype='transactionid'
.The normal way to check if the lock is acquired is to test the return value of
pg_try_advisory_xact_lock
.To test it after the fact looking up
pg_locks
, you could use the fact that it has been acquired by the current backend: