当前位置:网站首页>PG基础篇--逻辑结构管理(事务)
PG基础篇--逻辑结构管理(事务)
2022-07-06 12:42:00 【51CTO】
事务提交
pg默认是自动提交事务,可将自动提交功能关闭
关闭自动提交
savepoint
pg支持保存点功能,在一个大事务中,可以把操作过程分成几个部分,第一个部分执行成功后可以建一个保存点,若后面的部分执行失败,则回滚到此保存点,而不必回滚整个事务。
插入的第二条数据,回滚到第一个保存点。
事务隔离级别
和mysql一样,pg的事务隔离级别也分为4种,
read uncommited 读未提交
read commit读已提交
repeatable read 可重复读
serializable 串行化
脏读:一个事务读取了另一个事务未提交数据。
不可重复读:一个事务重新读取前面读取过的数据时,发现该数据已经被另一个事务修改过(update ,delete)。
幻读:一个事务开始后,查询符合条件的数据后,再次查询,发现多了数据(insert)。
pg可重复读可以避免不可重复读,但是避免不了幻读,这一点和mysql一样。不同点是pg默认的隔离级别是读已提交,而mysql默认是可重复读。
两阶段提交
在分布式系统中,事务中往往包含了多台数据库的操作,虽然单台数据库的操作能够保证原子性,但多台数据库之间的原子性就需要两阶段提交来实现了。
步骤
1)应用程序先调用各台数据库做一些操作,但不提交事务,然后应用程序调用事务协调器中的提交方法
2)事务协调器将联络事务中涉及的每台数据库,并通知它们准备提交事务,这是第一阶段的开始,就是调用PREPARE TRANSACTION。
3)各台数据库接收到PREPARE TRANSACTION后,如果返回成功,则数据库必须将自己置于如下状态:确保后续能在被提交事务的时候提价事务,或后续能在被要求回滚事务的时候回滚事务。所以PG会将已准备好提交的信息写入持久存储区中,如果数据库无法完成此事务,它会直接返回失败给事务协调器。
4)事务协调器接收所有数据库的响应。
5)第二阶段,如果任何一个数据库在第一阶段返回失败,则事务协调器将会发一个回滚命令给各台数据库,如果所有数据库的响应都是成功的,则向各台数据库发送commit prepared命令。通知各台数据库事务提交成功。
边栏推荐
- 1_ Introduction to go language
- 使用.Net分析.Net达人挑战赛参与情况
- B-jiege's tree (pressed tree DP)
- In unity space, an object moves around a fixed point on the sphere at a fixed speed
- APS taps home appliance industry into new growth points
- Learn to punch in Web
- Tencent byte and other big companies interview real questions summary, Netease architects in-depth explanation of Android Development
- Design your security architecture OKR
- Rhcsa Road
- 性能测试过程和计划
猜你喜欢

2022 Guangdong Provincial Safety Officer C certificate third batch (full-time safety production management personnel) simulation examination and Guangdong Provincial Safety Officer C certificate third

Anaconda安装后Jupyter launch 没反应&网页打开运行没执行

2022 refrigeration and air conditioning equipment installation and repair examination contents and new version of refrigeration and air conditioning equipment installation and repair examination quest

Utilisation de l'écran OLED

Kubernetes learning summary (20) -- what is the relationship between kubernetes and microservices and containers?
![Mécanisme de fonctionnement et de mise à jour de [Widget Wechat]](/img/cf/58a62a7134ff5e9f8d2f91aa24c7ac.png)
Mécanisme de fonctionnement et de mise à jour de [Widget Wechat]

Statistical inference: maximum likelihood estimation, Bayesian estimation and variance deviation decomposition

Application layer of tcp/ip protocol cluster

Database - how to get familiar with hundreds of tables of the project -navicat these unique skills, have you got it? (exclusive experience)

Detailed introduction of distributed pressure measurement system VIII: basic introduction of akka actor model
随机推荐
Tencent byte Alibaba Xiaomi jd.com offer got a soft hand, and the teacher said it was great
(work record) March 11, 2020 to March 15, 2021
APS taps home appliance industry into new growth points
Database - how to get familiar with hundreds of tables of the project -navicat these unique skills, have you got it? (exclusive experience)
"Penalty kick" games
[weekly pit] output triangle
Anaconda安装后Jupyter launch 没反应&网页打开运行没执行
8086 instruction code summary (table)
2022 Guangdong Provincial Safety Officer C certificate third batch (full-time safety production management personnel) simulation examination and Guangdong Provincial Safety Officer C certificate third
华为设备命令
Rhcsa Road
2022 construction electrician (special type of construction work) free test questions and construction electrician (special type of construction work) certificate examination
02 basic introduction - data package expansion
Is it safe to open an account in flush? Which securities company is good at opening an account? Low handling charges
报错分析~csdn反弹shell报错
永磁同步电机转子位置估算专题 —— 基波模型类位置估算概要
SQL injection 2
Taylor series fast Fourier transform (FFT)
How to select several hard coded SQL rows- How to select several hardcoded SQL rows?
Quel genre de programmation les enfants apprennent - ils?