- 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.
- Internet接入·網絡安全
- Google Cloud Platform Cookbook
- 三菱FX3U/5U PLC從入門到精通
- 計算機圖形學
- Python Artificial Intelligence Projects for Beginners
- 圖解PLC控制系統梯形圖和語句表
- OpenStack Cloud Computing Cookbook(Second Edition)
- Embedded Programming with Modern C++ Cookbook
- AutoCAD 2012中文版繪圖設計高手速成
- 氣動系統裝調與PLC控制
- SAP Business Intelligence Quick Start Guide
- Godot Engine Game Development Projects
- 基于Proteus的單片機應用技術
- 未來學徒:讀懂人工智能飛馳時代
- 工業機器人操作