PostgreSQL DBA(75) - Locks(locktype:transactionid):What You Should Know

本文探讨了PostgreSQL中locktype为transactionid的锁,解释了每个事务在其虚拟交易ID上持有独占锁的原理,并阐述了当一个事务等待另一个事务结束时,通过尝试获取共享锁的情况。重点是解决因未提交的行修改导致的锁定问题。
摘要由CSDN通过智能技术生成

本文简单介绍了PostgreSQL Locks(locktype:transactionid)的基础知识.
PostgreSQL系统表pg_locks中的locktype,有一种称为transactionid的锁类型,PG文档的说法是:

Every transaction holds an exclusive lock on its virtual transaction ID for its entire duration. If a permanent ID is assigned to the transaction (which normally happens only if the transaction changes the state of the database), it also holds an exclusive lock on its permanent transaction ID until it ends. When one transaction finds it necessary to wait specifically for another transaction, it does so by attempting to acquire share lock on the other transaction ID (either virtual or permanent ID depending on the situation). That will succeed only when the other transaction terminates and releases its locks.

In Postgres, every transaction takes an exclusive lock on its own transactionid when it starts. Sometimes, when a transaction wants to wait for another transaction to complete, it’ll try to take share lock on that other transaction’s id.This will of course block until the exclusive lock goes away.

Currently, the only case where anything will try to take a sharelock on transaction id is when it is blocking on a row-level lock as a result of trying to modify or delete or SELECT FOR UPDATE/FOR SHARE a row that the

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值