- Mastering PostgreSQL 10
- Hans Jürgen Sch?nig
- 312字
- 2021-06-30 19:03:51
Understanding transaction isolation levels
Up until now, you have seen how to handle locking as well as some basic concurrency. In this section, you will learn 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 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 the 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 this, you can use TRANSACTION ISOLATION LEVEL REPEATABLE READ. In this transaction isolation level, a transaction will use the same snapshot through the entire transaction. 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, the 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.
- 電氣自動化專業(yè)英語(第3版)
- Practical Data Analysis
- Mastering Proxmox(Third Edition)
- 精通MATLAB圖像處理
- Ansible Quick Start Guide
- Practical Data Wrangling
- 來吧!帶你玩轉(zhuǎn)Excel VBA
- Hands-On Cloud Solutions with Azure
- Cloud Analytics with Microsoft Azure
- 完全掌握AutoCAD 2008中文版:綜合篇
- Android游戲開發(fā)案例與關鍵技術
- INSTANT Drools Starter
- PostgreSQL 10 Administration Cookbook
- 深度學習與目標檢測
- Mastering Geospatial Analysis with Python