http://www.postgresql.org/docs/9.1/static/transaction-iso.html 关于读提交隔离级别的文档说
Read Committed is the default isolation level in PostgreSQL. When a transaction uses this isolation level, a SELECT query (without a FOR UPDATE/SHARE clause) sees only data committed before the query began; it never sees either uncommitted data or changes committed during query execution by concurrent transactions. In effect, a SELECT query sees a snapshot of the database as of the instant the query begins to run. However, SELECT does see the effects of previous updates executed within its own transaction, even though they are not yet committed. Also note that two successive SELECT commands can see different data, even though they are within a single transaction, if other transactions commit changes during execution of the first SELECT.
最后一句话让我很困惑,这是什么意思?如果我在一个事务中没有 2 个选择,而是 3 个选择,并且还有一些计算,并且在它们之间没有使用 DML,该怎么办?每个选择都会在每个查询开始时看到它自己的快照?
最佳答案
最后一句就是指这种情况。
假设在两个事务开始之前有一个表 foo
包含一行:
Transaction 1 Transaction 2 ------------------------------------------------------- begin transaction; select * from foo; --> returns 1 rows begin transaction; insert into foo values (2); commit; select * from foo; --> now returns 2 rows
(请注意,事务1在第一次选择后尚未提交)
如果您不想在事务 1 中看到新的(已提交的)行,则需要使用称为“可重复读”的隔离级别。该名称源于这样一个事实:您可以一次又一次重复相同的查询,并且您将重复看到相同的数据。
关于postgresql - 选择使用已提交读,请澄清,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23441243/