当前位置:网站首页>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 .
边栏推荐
猜你喜欢

Pytest (3) - Test naming rules

小孩子学什么编程?

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

OLED屏幕的使用

1_ Introduction to go language

I've seen many tutorials, but I still can't write a program well. How can I break it?

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,

Distributed ID
![[diy] how to make a personalized radio](/img/fc/a371322258131d1dc617ce18490baf.jpg)
[diy] how to make a personalized radio

硬件开发笔记(十): 硬件开发基本流程,制作一个USB转RS232的模块(九):创建CH340G/MAX232封装库sop-16并关联原理图元器件
随机推荐
SQL injection 2
Quel genre de programmation les enfants apprennent - ils?
What is the difference between procedural SQL and C language in defining variables
Xcode6 error: "no matching provisioning profiles found for application"
User defined current limiting annotation
Extraction rules and test objectives of performance test points
2110 summary of knowledge points and common problems in redis class
【每周一坑】输出三角形
Unity load AB package
设计你的安全架构OKR
全网最全的新型数据库、多维表格平台盘点 Notion、FlowUs、Airtable、SeaTable、维格表 Vika、飞书多维表格、黑帕云、织信 Informat、语雀
01 basic introduction - concept nouns
Use of OLED screen
1500萬員工輕松管理,雲原生數據庫GaussDB讓HR辦公更高效
[DSP] [Part 2] understand c6678 and create project
Catch ball game 1
Pytest (3) - Test naming rules
新型数据库、多维表格平台盘点 Notion、FlowUs、Airtable、SeaTable、维格表 Vika、飞书多维表格、黑帕云、织信 Informat、语雀
[weekly pit] information encryption + [answer] positive integer factorization prime factor
Intel 48 core new Xeon run point exposure: unexpected results against AMD zen3 in 3D cache