当前位置:网站首页>PG basics -- Logical Structure Management (transaction)
PG basics -- Logical Structure Management (transaction)
2022-07-06 20:49:00 【51CTO】
Transaction submission
pg The default is to automatically commit transactions , You can turn off the automatic submission function
Turn off auto submit
savepoint
pg Support savepoint function , In a big business , The operation process can be divided into several parts , After the first part is successfully executed, a savepoint can be created , If the later part fails , Rollback to this savepoint , Instead of rolling back the entire transaction .
The second data inserted , Rollback to the first savepoint .
Transaction isolation level
and mysql equally ,pg The transaction isolation level of is also divided into 4 Kind of ,
read uncommited Read uncommitted
read commit Read submitted
repeatable read Repeatable
serializable Serialization
Dirty reading : One transaction reads uncommitted data from another transaction .
It can't be read repeatedly : When a transaction re reads the previously read data , It is found that the data has been modified by another transaction (update ,delete).
Fantasy reading : After a transaction has started , After querying the qualified data , Query again , More data found (insert).
pg Repeatable reading can avoid non repeatable reading , But unreal reading cannot be avoided , This and mysql equally . The difference is pg The default isolation level is read committed , and mysql The default is repeatable reading .
Two-phase commit
In distributed systems , Transactions often involve the operation of multiple databases , Although the operation of a single database can ensure atomicity , However, atomicity between multiple databases requires two-stage submission .
step
1) The application program first calls each database to do some operations , But don't commit the transaction , Then the application calls the commit method in the transaction coordinator
2) The transaction coordinator will contact each database involved in the transaction , And inform them that they are ready to commit the transaction , This is the beginning of the first phase , It's called PREPARE TRANSACTION.
3) Each database receives PREPARE TRANSACTION after , If the return is successful , Then the database must put itself in the following state : Ensure that subsequent transactions can be raised when they are submitted , Or the transaction can be rolled back later when required . therefore PG The information ready for submission will be written to the persistent storage , If the database cannot complete this transaction , It will directly return the failure to the transaction coordinator .
4) The transaction coordinator receives responses from all databases .
5) The second stage , If any database fails in the first stage , Then the transaction coordinator will send a rollback command to each database , If all database responses are successful , Send to each database commit prepared command . Notify each database that the transaction is submitted successfully .
边栏推荐
- Rhcsa Road
- OLED屏幕的使用
- 动态切换数据源
- 自定义限流注解
- 【微信小程序】运行机制和更新机制
- 2022 construction electrician (special type of construction work) free test questions and construction electrician (special type of construction work) certificate examination
- Spiral square PTA
- Detailed explanation of knowledge map construction process steps
- Pinduoduo lost the lawsuit, and the case of bargain price difference of 0.9% was sentenced; Wechat internal test, the same mobile phone number can register two account functions; 2022 fields Awards an
- 小孩子學什麼編程?
猜你喜欢
随机推荐
OLED屏幕的使用
性能测试过程和计划
How to turn a multi digit number into a digital list
Database - how to get familiar with hundreds of tables of the project -navicat these unique skills, have you got it? (exclusive experience)
Mécanisme de fonctionnement et de mise à jour de [Widget Wechat]
Catch ball game 1
How does kubernetes support stateful applications through statefulset? (07)
Event center parameter transfer, peer component value transfer method, brother component value transfer
2110 summary of knowledge points and common problems in redis class
[weekly pit] output triangle
Unity writes a timer tool to start timing from the whole point. The format is: 00:00:00
Function optimization and arrow function of ES6
[weekly pit] information encryption + [answer] positive integer factorization prime factor
Laravel notes - add the function of locking accounts after 5 login failures in user-defined login (improve system security)
逻辑是个好东西
No Yum source to install SPuG monitoring
华为设备命令
Unity making plug-ins
Boder radius has four values, and boder radius exceeds four values
Distributed ID







