怎么理解PostgreSQL Locks中的Lock Manager Internal Locking
发表于:2025-11-12 作者:千家信息网编辑
千家信息网最后更新 2025年11月12日,本篇内容主要讲解"怎么理解PostgreSQL Locks中的Lock Manager Internal Locking",感兴趣的朋友不妨来看看。本文介绍的方法操作简单快捷,实用性强。下面就让小编来
千家信息网最后更新 2025年11月12日怎么理解PostgreSQL Locks中的Lock Manager Internal Locking
本篇内容主要讲解"怎么理解PostgreSQL Locks中的Lock Manager Internal Locking",感兴趣的朋友不妨来看看。本文介绍的方法操作简单快捷,实用性强。下面就让小编来带大家学习"怎么理解PostgreSQL Locks中的Lock Manager Internal Locking"吧!
一、Lock Manager Internal Locking
Lock Manager Internal Locking-----------------------------内部锁机制Before PostgreSQL 8.2, all of the shared-memory data structures used bythe lock manager were protected by a single LWLock, the LockMgrLock;any operation involving these data structures had to exclusively lockLockMgrLock. Not too surprisingly, this became a contention bottleneck.To reduce contention, the lock manager's data structures have been splitinto multiple "partitions", each protected by an independent LWLock.Most operations only need to lock the single partition they are working in.Here are the details:在PG 8.2或更旧的版本中,共享缓存中的数据结构通过一个单一的LWLock(LockMgrLock)保护;涉及这些数据结构的所有操作必须持有LockMgrLock独占锁.不用说太多,这会成为争用的瓶颈.为了减少争用,锁管理器数据结构已拆分为多个"partitions",每一个分区使用独立的LWLock保护.大多数操作只需要锁定其中一个分区,下面是实现细节:* Each possible lock is assigned to one partition according to a hash ofits LOCKTAG value. The partition's LWLock is considered to protect all theLOCK objects of that partition as well as their subsidiary PROCLOCKs.* 只需要授予属于LOCKTAG哈希值的某个分区的锁,分区的LWLock用于保护该分区的所有LOCK对象.* The shared-memory hash tables for LOCKs and PROCLOCKs are organizedso that different partitions use different hash chains, and thus thereis no conflict in working with objects in different partitions. Thisis supported directly by dynahash.c's "partitioned table" mechanismfor the LOCK table: we need only ensure that the partition number istaken from the low-order bits of the dynahash hash value for the LOCKTAG.To make it work for PROCLOCKs, we have to ensure that a PROCLOCK's hashvalue has the same low-order bits as its associated LOCK. This requiresa specialized hash function (see proclock_hash).LOCKs和PROCLOCKs被组织为存储在共享内存中哈希表以便不同的分区使用不同的哈希链,这样不同分区中的对象就不会出现冲突,通过dynahash.c's "partitioned table"机制实现.只需要确保分区号从LOCKTAG的dynahash哈希值的低位中获取即可.对于PROCLOCKs,必须确保PROCLOCK的哈希值有与LOCK有相同的低位.这需要特别的哈希函数(proclock_hash)* Formerly, each PGPROC had a single list of PROCLOCKs belonging to it.This has now been split into per-partition lists, so that access to aparticular PROCLOCK list can be protected by the associated partition'sLWLock. (This rule allows one backend to manipulate another backend'sPROCLOCK lists, which was not originally necessary but is now required inconnection with fast-path locking; see below.)以前的做法,每一个PGPROC都有一个单独的PROCLOCKs链表.现在已拆分为每一个分区一个链表,这样的好处是访问一个PROCLOCK链表可通过相关的分区LWLock保护.(这个规则允许一个后台进程可管理另外一个后台进程的PROCLOCK链表,这个事情本来是不需要做的,但现在在使用fast-path锁的连接时需要)* The other lock-related fields of a PGPROC are only interesting whenthe PGPROC is waiting for a lock, so we consider that they are protectedby the partition LWLock of the awaited lock.PGPROC中与锁相关的域只在PRPROC等待锁才会变得有用,因此我们考虑通过分区LWLOCK中awaited lock来进行保护.For normal lock acquisition and release, it is sufficient to lock thepartition containing the desired lock. Deadlock checking needs to touchmultiple partitions in general; for simplicity, we just make it lock allthe partitions in partition-number order. (To prevent LWLock deadlock,we establish the rule that any backend needing to lock more than onepartition at once must lock them in partition-number order.) It'spossible that deadlock checking could be done without touching everypartition in typical cases, but since in a properly functioning systemdeadlock checking should not occur often enough to be performance-critical,trying to make this work does not seem a productive use of effort.对于普通的锁请求和释放,锁定包含目标锁的分区就已经足够了.通常来说,死锁检测需要访问多个分区.简单来说,我们只要按分区顺序锁定相关的所有分区即可.(为了避免LWLock死锁,设定的规则是所有需要锁定一个以上分区的后台进程必须一次过按顺序所有所有分区)在典型情况下,不需要访问每一个分区进行死锁检测是可以做到的,但因为在一个正常运行的系统中,死锁检测不应经常发生,因此不会对性能造成较大的影响.A backend's internal LOCALLOCK hash table is not partitioned. We do storea copy of the locktag hash code in LOCALLOCK table entries, from which thepartition number can be computed, but this is a straight speed-for-spacetradeoff: we could instead recalculate the partition number from the LOCKTAGwhen needed.后台进程的内部LOCALLOCK哈希表没有分区.我们确实在LOCALLOCK表条目中存储了locktag哈希值的副本,分区号可以计算,这是一个以空间换时间的考量:我们可以从LOCKTAG重新计算分区号.
到此,相信大家对"怎么理解PostgreSQL Locks中的Lock Manager Internal Locking"有了更深的了解,不妨来实际操作一番吧!这里是网站,更多相关内容可以进入相关频道进行查询,关注我们,继续学习!
哈希
保护
后台
进程
死锁
不同
数据
数据结构
结构
检测
低位
内容
多个
对象
机制
规则
顺序
存储
学习
管理
数据库的安全要保护哪些东西
数据库安全各自的含义是什么
生产安全数据库录入
数据库的安全性及管理
数据库安全策略包含哪些
海淀数据库安全审计系统
建立农村房屋安全信息数据库
易用的数据库客户端支持安全管理
连接数据库失败ssl安全错误
数据库的锁怎样保障安全
怎么在软件开发中用到解释器
合肥竹鼠软件开发
2018三级网络技术资料
数据库的软件技术
疫情期间网络安全教育小学生
江苏综合软件开发制造价格
合肥软件开发技术
分发网络安全告家长书信息报道
个人信用信息网络安全保护
数据库死锁答题
三级网络技术辅导章节
服务器能一直开吗
中国网络安全大赛报名
韵达数据库技术
pc方舟服务器永久多少钱
网络安全比赛奖杯
河南cdma授时服务器云主机
学习360网络安全专业好吗
如何清理系统自带数据库
电商app模板软件开发
图数据库开源方案
服务器管理工具由什么程序提供
黑客网络安全比赛
软件开发规模估算
Gps轨迹从数据库中实时查询
餐饮信息软件开发用到的工具
山西网络技术开发哪家好
网信部门贯彻落实网络安全法
目前软件开发技术水平
计算机网络技术基础护肤顺序