当前位置:网站首页>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 .
边栏推荐
- Logic is a good thing
- Xcode6 error: "no matching provisioning profiles found for application"
- Tips for web development: skillfully use ThreadLocal to avoid layer by layer value transmission
- 请问sql group by 语句问题
- Dynamically switch data sources
- Is it safe to open an account in flush? Which securities company is good at opening an account? Low handling charges
- 正则表达式收集
- Learn to punch in Web
- Number of schemes from the upper left corner to the lower right corner of the chessboard (2)
- OSPF多区域配置
猜你喜欢

2022 construction electrician (special type of construction work) free test questions and construction electrician (special type of construction work) certificate examination

设计你的安全架构OKR
![[200 opencv routines] 220 Mosaic the image](/img/75/0293e10ad6de7ed86df4cacbd79b54.png)
[200 opencv routines] 220 Mosaic the image

看过很多教程,却依然写不好一个程序,怎么破?

【DSP】【第二篇】了解C6678和创建工程

知识图谱构建流程步骤详解

Entity alignment two of knowledge map

How does kubernetes support stateful applications through statefulset? (07)
Tencent byte and other big companies interview real questions summary, Netease architects in-depth explanation of Android Development

【每周一坑】正整数分解质因数 +【解答】计算100以内质数之和
随机推荐
01 basic introduction - concept nouns
过程化sql在定义变量上与c语言中的变量定义有什么区别
OLED屏幕的使用
Logic is a good thing
Mécanisme de fonctionnement et de mise à jour de [Widget Wechat]
Infrared thermometer based on STM32 single chip microcomputer (with face detection)
02 basic introduction - data package expansion
Pycharm remote execution
[weekly pit] output triangle
1500万员工轻松管理,云原生数据库GaussDB让HR办公更高效
The mail command is used in combination with the pipeline command statement
Basic knowledge of lists
Huawei device command
Pytest (3) - Test naming rules
APS taps home appliance industry into new growth points
逻辑是个好东西
Comprehensive evaluation and recommendation of the most comprehensive knowledge base management tools in the whole network: flowus, baklib, jiandaoyun, ones wiki, pingcode, seed, mebox, Yifang cloud,
Leetcode question 448 Find all missing numbers in the array
C language games - minesweeping
Force deduction brush question - 98 Validate binary search tree