当前位置:网站首页>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 .
边栏推荐
- Gui Gui programming (XIII) - event handling
- 正则表达式收集
- Implementation of packaging video into MP4 format and storing it in TF Card
- Core principles of video games
- [DSP] [Part 1] start DSP learning
- Laravel notes - add the function of locking accounts after 5 login failures in user-defined login (improve system security)
- 【每周一坑】计算100以内质数之和 +【解答】输出三角形
- Boder radius has four values, and boder radius exceeds four values
- 【微信小程序】運行機制和更新機制
- Tencent T4 architect, Android interview Foundation
猜你喜欢
Performance test process and plan
小孩子学什么编程?
逻辑是个好东西
The mail command is used in combination with the pipeline command statement
Basic knowledge of lists
##无yum源安装spug监控
硬件开发笔记(十): 硬件开发基本流程,制作一个USB转RS232的模块(九):创建CH340G/MAX232封装库sop-16并关联原理图元器件
Infrared thermometer based on STM32 single chip microcomputer (with face detection)
[wechat applet] operation mechanism and update mechanism
Maximum likelihood estimation and cross entropy loss
随机推荐
为什么新手在编程社区提问经常得不到回答,甚至还会被嘲讽?
【每周一坑】输出三角形
看过很多教程,却依然写不好一个程序,怎么破?
小孩子学什么编程?
Infrared thermometer based on STM32 single chip microcomputer (with face detection)
B-jiege's tree (pressed tree DP)
Summary of different configurations of PHP Xdebug 3 and xdebug2
Detailed explanation of knowledge map construction process steps
知识图谱之实体对齐二
Trends of "software" in robotics Engineering
[DIY]如何制作一款个性的收音机
How to turn a multi digit number into a digital list
什么是RDB和AOF
Xcode6 error: "no matching provisioning profiles found for application"
Intel 48 core new Xeon run point exposure: unexpected results against AMD zen3 in 3D cache
Statistical inference: maximum likelihood estimation, Bayesian estimation and variance deviation decomposition
Pytest (3) - Test naming rules
自定义限流注解
7、数据权限注解
Recyclerview GridLayout bisects the middle blank area