当前位置:网站首页>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 .
边栏推荐
- C language games - three chess
- [DIY]自己设计微软MakeCode街机,官方开源软硬件
- What programming do children learn?
- Tencent byte and other big companies interview real questions summary, Netease architects in-depth explanation of Android Development
- 什么是RDB和AOF
- 小孩子學什麼編程?
- Boder radius has four values, and boder radius exceeds four values
- recyclerview gridlayout 平分中间空白区域
- JS implementation force deduction 71 question simplified path
- Common doubts about the introduction of APS by enterprises
猜你喜欢
Design your security architecture OKR
【每周一坑】信息加密 +【解答】正整数分解质因数
No Yum source to install SPuG monitoring
[weekly pit] calculate the sum of primes within 100 + [answer] output triangle
JMeter server resource indicator monitoring (CPU, memory, etc.)
使用.Net分析.Net达人挑战赛参与情况
Gui Gui programming (XIII) - event handling
15million employees are easy to manage, and the cloud native database gaussdb makes HR office more efficient
[asp.net core] set the format of Web API response data -- formatfilter feature
Intel 48 core new Xeon run point exposure: unexpected results against AMD zen3 in 3D cache
随机推荐
What key progress has been made in deep learning in 2021?
全网最全的知识库管理工具综合评测和推荐:FlowUs、Baklib、简道云、ONES Wiki 、PingCode、Seed、MeBox、亿方云、智米云、搜阅云、天翎
How to select several hard coded SQL rows- How to select several hardcoded SQL rows?
Number of schemes from the upper left corner to the lower right corner of the chessboard (2)
【DSP】【第一篇】开始DSP学习
Reinforcement learning - learning notes 5 | alphago
Rhcsa Road
Build your own application based on Google's open source tensorflow object detection API video object recognition system (IV)
Comment faire une radio personnalisée
Tencent byte and other big companies interview real questions summary, Netease architects in-depth explanation of Android Development
use. Net analysis Net talent challenge participation
(工作记录)2020年3月11日至2021年3月15日
Simple continuous viewing PTA
Use of OLED screen
C language games - three chess
Statistical inference: maximum likelihood estimation, Bayesian estimation and variance deviation decomposition
【每周一坑】信息加密 +【解答】正整数分解质因数
Rhcsa Road
1_ Introduction to go language
Detailed explanation of knowledge map construction process steps