Reading Committed State from Another Transaction

A database's isolation rules determine which other writes a query can observe, including whether they must have committed.

Source
Anbloq
Language
English
Created
Updated
Chapters
4
Reading time
1 min
In this article4 chapters
  1. Trace two sessions
  2. Check a later statement
  3. Observe a write before and after commit on two connections
  4. Keep isolation and timing visible during the test

Trace two sessions

One PostgreSQL session edits a title and leaves its transaction open. Another session under Read Committed cannot see that uncommitted edit in its ordinary read. Transaction anomalies describe the visibility contract.

Check a later statement

After the first transaction commits, a new statement in the second session can see the updated value under ordinary Read Committed rules. A report that uses one snapshot for multiple reads makes a different visibility promise.[1]

Observe a write before and after commit on two connections

Writer A updates a value from three to nine inside a transaction. Under PostgreSQL read committed isolation an ordinary read by B while the write remains uncommitted sees the earlier committed value. A later statement can see nine once A commits. See choosing a report snapshot.

A begins and writes 9
B reads before commit → 3 under this model
A commits
B's later statement → can see 9

Keep isolation and timing visible during the test

Use independent connections and explicit synchronization instead of guessing event order from delays. Test both commit and rollback. Locking reads and other engines may give different timing or behavior.

References

  1. PostgreSQL Global Development Group, Transaction Isolation ↩