当前位置:网站首页>PG basics -- Logical Structure Management (locking mechanism -- table lock)
PG basics -- Logical Structure Management (locking mechanism -- table lock)
2022-07-07 14:49:00 【51CTO】
pg There are two types of locks , Table level lock and row level lock .
Table lock
Table lock classification
ACCESS SHARE | Read only tables do not modify the table to apply for the lock mode | |
ROW SHARE | select for update and select for share Apply for the lock mode | |
ROW EXCLUSIVE | DML Apply for the lock mode | |
SHARE UPDATE EXCLUSIVE | VACUUM、ANALYZE、CREATE INDEX CONCURRENTLY Apply for the lock mode | |
SHARE | create index Apply for the lock mode | |
SHARE ROW EXCLUSIVE | Won't apply voluntarily | |
EXCLUSIVE | Won't apply voluntarily | |
ACCESS EXCLUSIVE | alter table ,drop table,truncate,reindex ,vacuum full Apply for the lock of this mode | |
Table lock overview
Table lock only share and EXCLUSIVE Two kinds of , That is, read and write lock ,share The table cannot be modified after the read lock is added , Lock exclusive You cannot read or write after writing the lock , But after the multi version function , Modify a row of data , In fact, it doesn't change the original line , Instead, another row of data is copied , The modification is made on the new line , The transaction does not commit , Others cannot see the modified line , There is no need to block other users from reading data .
Under the multi version function ,ACCESS share Indicates that this lock is added , Even when the data is being modified , It is also allowed to read data , Another lock ACCESS EXCLUSIVE Even multi version features , Access to data is also not allowed .
Intent locks
The lock granularity of table lock is too large , There's a row level lock ,mysql Before obtaining row lock, you need to obtain intention lock ,pg It's similar to mysql Also have ROW_SHARE and ROW_EXCLUSIVE lock .
There is no conflict between intent locks , The conflict compatibility relationship between intentional and non intentional locks is the same as that between ordinary locks . It can be simply converted to X and S, Comparing compatibility .
SHARE UPDATE EXCLUSIVE
Is to put IX The incompatibility between locks becomes a more strict lock , For without FULL Of VACUUM,CREATE INDEX CONCURRENTLY Will apply for the lock .
SHAER ROW EXCLUSIVE
Equivalent to adding S Lock and IX lock
Table lock summary
PG The Communist Party of China 8 Seed lock , Shared lock SHARE And lock it EXCLUSIVE , Colleagues who modify data due to multiple versions are allowed to read data , Hence the ACCESS SHARE and ACCESS EXCLUSIVE lock .
In order to deal with the relationship between table lock and row lock , The concept of intention lock ,ROW_SHARE and ROW_EXCLUSIVE lock , But there will be no conflict between intention locks , To be more strict , There is SHARE
UPDATE EXCLUSIVE and SHARE ROW EXCLUSIVE lock .
边栏推荐
- ⼀个对象从加载到JVM,再到被GC清除,都经历了什么过程?
- 6、Electron无边框窗口和透明窗口 锁定模式 设置窗口图标
- 云上“视界” 创新无限 | 2022阿里云直播峰会正式上线
- The method of parsing PHP to jump out of the loop and the difference between continue, break and exit
- AWS学习笔记(三)
- Internal sort - insert sort
- Leetcode——236. The nearest common ancestor of binary tree
- Source code analysis of ArrayList
- Excuse me, does PTS have a good plan for database pressure measurement?
- 2022云顾问技术系列之高可用专场分享会
猜你喜欢

WebRTC 音频抗弱网技术(上)

Leetcode one question per day (636. exclusive time of functions)

JS get the current time, month, day, year, and the uniapp location applet opens the map to select the location

因员工将密码设为“123456”,AMD 被盗 450Gb 数据?

Today's sleep quality record 78 points

EfficientNet模型的完整细节

《微信小程序-进阶篇》组件封装-Icon组件的实现(一)

【服务器数据恢复】某品牌StorageWorks服务器raid数据恢复案例

Pytorch model trains practical skills and breaks through the bottleneck of speed

GAN发明者Ian Goodfellow正式加入DeepMind,任Research Scientist
随机推荐
Docker deploy Oracle
PyTorch模型训练实战技巧,突破速度瓶颈
Demis Hassabis谈AlphaFold未来目标
Cocos creator direction and angle conversion
FFmpeg----图片处理
Analysis of arouter
低代码平台中的数据连接方式(下)
Full details of efficientnet model
一个程序员的水平能差到什么程度?尼玛,都是人才呀...
Xiaomi's path of chip self-development
AWS learning notes (III)
The world's first risc-v notebook computer is on pre-sale, which is designed for the meta universe!
13 ux/ui/ue best creative inspiration websites in 2022
小程序目录结构
Lidar Knowledge Drop
内部排序——插入排序
一文读懂数仓中的pg_stat
Five pain points for big companies to open source
ES日志报错赏析-trying to create too many buckets
Internal sort - insert sort