当前位置:网站首页>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 .
边栏推荐
- OAuth 2.0 + JWT protect API security
- 多商戶商城系統功能拆解01講-產品架構
- ⼀个对象从加载到JVM,再到被GC清除,都经历了什么过程?
- Ascend 910实现Tensorflow1.15实现LeNet网络的minist手写数字识别
- 「2022年7月」WuKong编辑器更版记录
- Leetcode one question per day (636. exclusive time of functions)
- Leetcode——344. Reverse string /541 Invert string ii/151 Reverse the word / Sword finger in the string offer 58 - ii Rotate string left
- Docker deploy Oracle
- Cocoscreator resource encryption and decryption
- Substance Painter筆記:多顯示器且多分辨率顯示器時的設置
猜你喜欢
Cvpr2022 | backdoor attack based on frequency injection in medical image analysis
全球首款 RISC-V 笔记本电脑开启预售,专为元宇宙而生!
在软件工程领域,搞科研的这十年!
Navigation — 这么好用的导航框架你确定不来看看?
C 6.0 language specification approved
Pandora IOT development board learning (HAL Library) - Experiment 12 RTC real-time clock experiment (learning notes)
小米的芯片自研之路
低代码平台中的数据连接方式(下)
Spatiotemporal deformable convolution for compressed video quality enhancement (STDF)
Mrs offline data analysis: process OBS data through Flink job
随机推荐
Today's sleep quality record 78 points
PG基础篇--逻辑结构管理(锁机制--表锁)
Reading and understanding of eventbus source code
寺岗电子称修改IP简易步骤
用于增强压缩视频质量的可变形卷积密集网络
Leetcode——236. The nearest common ancestor of binary tree
Computer win7 system desktop icon is too large, how to turn it down
A laravel background management expansion package you can't miss - Voyager
JS get the current time, month, day, year, and the uniapp location applet opens the map to select the location
Delete a whole page in word
内部排序——插入排序
一文读懂数仓中的pg_stat
激光雷达lidar知识点滴
CPU与chiplet技术杂谈
Es log error appreciation -maximum shards open
华为云数据库DDS产品深度赋能
Es log error appreciation -- allow delete
Ffmpeg --- image processing
Simple use of websocket
PyTorch模型训练实战技巧,突破速度瓶颈