- Mastering PostgreSQL 9.6
- Hans Jurgen Schonig
- 289字
- 2021-07-09 19:57:13
Understanding transaction isolation levels
Up to now, you have seen how to handle locking as well as some basic concurrency. In this section, you will learn about transaction isolation. To me, this is one of the most neglected topics in modern software development. Only a small fraction of software developers are actually aware of this issue, which in turn leads to disgusting and mind-boggling bugs.
Here is an example of what can happen:

Most users would actually expect the left transaction to always return 300 regardless of the second transaction. However, this is not true. By default, PostgreSQL runs in READ COMMITTED transaction isolation mode. This means that every statement inside a transaction will get a new snapshot of the data, which will be constant throughout the query.
If you want to avoid that, you can use TRANSACTION ISOLATION LEVEL REPEATABLE READ. In this transaction isolation level, a transaction will use the same snapshot through the entire transactions. Here is what will happen:

As just outlined, the first transaction will freeze its snapshot of the data and provide us with constant results throughout the entire transaction. This feature is especially important if you want to run reports. The first and the last page of a report should always be consistent and operate on the same data. Therefore, repeatable read is key to consistent reports.
Note that isolation-related errors won't always pop up instantly. It can happen that trouble is noticed years after an application has been moved to production.
- 空間傳感器網(wǎng)絡(luò)復(fù)雜區(qū)域智能監(jiān)測技術(shù)
- 運(yùn)動(dòng)控制系統(tǒng)應(yīng)用與實(shí)踐
- 工業(yè)機(jī)器人運(yùn)動(dòng)仿真編程實(shí)踐:基于Android和OpenGL
- PowerMill 2020五軸數(shù)控加工編程應(yīng)用實(shí)例
- MPC5554/5553微處理器揭秘
- 運(yùn)動(dòng)控制系統(tǒng)(第2版)
- Cortex-M3嵌入式處理器原理與應(yīng)用
- 貫通Java Web輕量級(jí)應(yīng)用開發(fā)
- 30天學(xué)通Java Web項(xiàng)目案例開發(fā)
- 基于元胞自動(dòng)機(jī)的人群疏散系統(tǒng)建模與分析
- ROS Robotics By Example(Second Edition)
- ARM體系結(jié)構(gòu)與編程
- 輸送技術(shù)、設(shè)備與工業(yè)應(yīng)用
- Arduino創(chuàng)意機(jī)器人入門:基于Mind+
- PVCBOT零基礎(chǔ)機(jī)器人制作(第2版)