当前位置:网站首页>PG基础篇--逻辑结构管理(锁机制--表锁)
PG基础篇--逻辑结构管理(锁机制--表锁)
2022-07-07 12:43:00 【51CTO】
pg的锁有两类,表级锁和行级锁。
表级锁
表级锁分类
ACCESS SHARE | 只读表不修改表申请该锁模式 | |
ROW SHARE | select for update 和select for share 申请该锁模式 | |
ROW EXCLUSIVE | DML申请该锁模式 | |
SHARE UPDATE EXCLUSIVE | VACUUM、ANALYZE、CREATE INDEX CONCURRENTLY申请该锁模式 | |
SHARE | create index 申请该锁模式 | |
SHARE ROW EXCLUSIVE | 不会主动申请 | |
EXCLUSIVE | 不会主动申请 | |
ACCESS EXCLUSIVE | alter table ,drop table,truncate,reindex ,vacuum full 申请该模式的锁 | |
表级锁概述
表级锁只有share和EXCLUSIVE两种,也就是读和写锁,share读锁加上后不能修改表,加锁exclusive写锁后不能读也不能写,但是在多版本功能后,修改某一行数据,实际上并没有改变原来那一行,而是另复制了一行数据,修改在新行上进行,事务不提交,别人是看不到修改行的,就没有必要阻塞其他用户读数据了。
在多版本功能下,ACCESS share 表明加上这个锁,即使是正在修改数据的情况下,也允许读数据,另一个锁ACCESS EXCLUSIVE 即使多版本功能,也不允许访问数据。
意向锁
表级锁的锁粒度太大,出现了行级锁,mysql获得行锁之前需要获取意向锁,pg中类似mysql也有ROW_SHARE 和ROW_EXCLUSIVE锁。
意向锁之间不会冲突,意向锁和非意向锁的冲突兼容关系和普通锁之间关系一样。可以简单转换为X和S,在比较是否兼容。
SHARE UPDATE EXCLUSIVE
就是把IX锁之间的不兼容变为更严格的一种锁,针对不带FULL的VACUUM,CREATE INDEX CONCURRENTLY都会申请该锁。
SHAER ROW EXCLUSIVE
等同于加了S锁和IX锁
表锁总结
PG中共8种锁,共享锁SHARE 和排它锁EXCLUSIVE ,因为多版本的原因修改数据的同事允许读数据,于是有了ACCESS SHARE和ACCESS EXCLUSIVE锁。
为了处理表锁和行锁之间的关系,欧了意向锁的概念,ROW_SHARE 和ROW_EXCLUSIVE锁,但是意向锁之间不会冲突,为了更严格,出现了SHARE
UPDATE EXCLUSIVE和 SHARE ROW EXCLUSIVE锁。
边栏推荐
- Data connection mode in low code platform (Part 2)
- Half an hour of hands-on practice of "live broadcast Lianmai construction", college students' resume of technical posts plus points get!
- Equipment failure prediction machine failure early warning mechanical equipment vibration monitoring machine failure early warning CNC vibration wireless monitoring equipment abnormal early warning
- Leetcode——344. Reverse string /541 Invert string ii/151 Reverse the word / Sword finger in the string offer 58 - ii Rotate string left
- GVIM [III] [u vimrc configuration]
- 6. Electron borderless window and transparent window lock mode setting window icon
- WPF DataGrid realizes the UI interface to respond to a data change in a single line
- 因员工将密码设为“123456”,AMD 被盗 450Gb 数据?
- Hangdian oj2054 a = = B? ???
- C# 6.0 语言规范获批
猜你喜欢

Mmkv use and principle

低代码平台中的数据连接方式(下)

Computer win7 system desktop icon is too large, how to turn it down

Mrs offline data analysis: process OBS data through Flink job

今日睡眠质量记录78分

Navigation - are you sure you want to take a look at such an easy-to-use navigation framework?

Full details of efficientnet model

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

MRS离线数据分析:通过Flink作业处理OBS数据

在软件工程领域,搞科研的这十年!
随机推荐
Differences between cookies and sessions
Leetcode——344. Reverse string /541 Invert string ii/151 Reverse the word / Sword finger in the string offer 58 - ii Rotate string left
设备故障预测机床故障提前预警机械设备振动监测机床故障预警CNC震动无线监控设备异常提前预警
Leetcode one question per day (636. exclusive time of functions)
Navigation - are you sure you want to take a look at such an easy-to-use navigation framework?
MLGO:Google AI发布工业级编译器优化机器学习框架
WebRTC 音频抗弱网技术(上)
昇腾体验官第五期随手记I
一个程序员的水平能差到什么程度?尼玛,都是人才呀...
Internal sort - insert sort
Substance painter notes: settings for multi display and multi-resolution displays
ES日志报错赏析-maximum shards open
PD virtual machine tutorial: how to set the available shortcut keys in the parallelsdesktop virtual machine?
Cascading update with Oracle trigger
Million data document access of course design
2022年13个UX/UI/UE最佳创意灵感网站
多商戶商城系統功能拆解01講-產品架構
Cvpr2022 | backdoor attack based on frequency injection in medical image analysis
KITTI数据集简介与使用
在软件工程领域,搞科研的这十年!