当前位置:网站首页>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 .
边栏推荐
- 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
- [weekly pit] calculate the sum of primes within 100 + [answer] output triangle
- Boder radius has four values, and boder radius exceeds four values
- Unity making plug-ins
- Performance test process and plan
- 2022 nurse (primary) examination questions and new nurse (primary) examination questions
- SSO single sign on
- Tips for web development: skillfully use ThreadLocal to avoid layer by layer value transmission
- Zoom with unity mouse wheel: zoom the camera closer or farther
- 请问sql group by 语句问题
猜你喜欢
Mécanisme de fonctionnement et de mise à jour de [Widget Wechat]
[200 opencv routines] 220 Mosaic the image
Logic is a good thing
全网最全的新型数据库、多维表格平台盘点 Notion、FlowUs、Airtable、SeaTable、维格表 Vika、飞书多维表格、黑帕云、织信 Informat、语雀
Hardware development notes (10): basic process of hardware development, making a USB to RS232 module (9): create ch340g/max232 package library sop-16 and associate principle primitive devices
Error analysis ~csdn rebound shell error
设计你的安全架构OKR
【每周一坑】正整数分解质因数 +【解答】计算100以内质数之和
[diy] self designed Microsoft makecode arcade, official open source software and hardware
[wechat applet] operation mechanism and update mechanism
随机推荐
Summary of different configurations of PHP Xdebug 3 and xdebug2
2022 nurse (primary) examination questions and new nurse (primary) examination questions
Maximum likelihood estimation and cross entropy loss
新型数据库、多维表格平台盘点 Notion、FlowUs、Airtable、SeaTable、维格表 Vika、飞书多维表格、黑帕云、织信 Informat、语雀
Utilisation de l'écran OLED
Taylor series fast Fourier transform (FFT)
How to upgrade high value-added links in the textile and clothing industry? APS to help
What is the difference between procedural SQL and C language in defining variables
Use of OLED screen
Pytest (3) - Test naming rules
【DSP】【第二篇】了解C6678和创建工程
硬件开发笔记(十): 硬件开发基本流程,制作一个USB转RS232的模块(九):创建CH340G/MAX232封装库sop-16并关联原理图元器件
Recyclerview GridLayout bisects the middle blank area
OLED屏幕的使用
Database - how to get familiar with hundreds of tables of the project -navicat these unique skills, have you got it? (exclusive experience)
Spark SQL chasing Wife Series (initial understanding)
Can novices speculate in stocks for 200 yuan? Is the securities account given by qiniu safe?
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
华为设备命令
[DSP] [Part 2] understand c6678 and create project