0
0
PostgreSQLquery~10 mins

Read committed behavior in PostgreSQL - Step-by-Step Execution

Choose your learning style9 modes available
Concept Flow - Read committed behavior
Start Transaction T1
T1 reads data
Start Transaction T2
T2 modifies and commits data
T1 reads data again
T1 sees T2's committed changes
T1 commits or rolls back
In Read Committed, each query sees only data committed before it started, so a transaction can see changes committed by others between its queries.
Execution Sample
PostgreSQL
BEGIN;
SELECT balance FROM accounts WHERE id=1;
-- T2 updates balance and commits
SELECT balance FROM accounts WHERE id=1;
COMMIT;
Transaction T1 reads a balance, then after T2 commits an update, T1 reads the updated balance.
Execution Table
StepTransactionActionData ReadData State
1T1BEGIN transactionN/ABalance=100
2T1SELECT balance100Balance=100
3T2BEGIN transactionN/ABalance=100
4T2UPDATE balance=150N/ABalance=150 (uncommitted)
5T2COMMITN/ABalance=150 (committed)
6T1SELECT balance150Balance=150 (committed)
7T1COMMITN/ABalance=150
💡 T1 ends after seeing T2's committed update in its second read.
Variable Tracker
VariableStartAfter Step 2After Step 5After Step 6Final
balance100100150150150
Key Moments - 2 Insights
Why does T1 see the updated balance 150 in step 6 but not in step 2?
Because in Read Committed, each query sees only data committed before it starts. At step 2, T2's update was not committed yet, but by step 6, T2 committed, so T1 sees the new value.
Does T1 see uncommitted changes from T2 during its transaction?
No. T1 only sees committed data at the start of each query, so uncommitted changes by T2 are invisible to T1.
Visual Quiz - 3 Questions
Test your understanding
Look at the execution table, what is the balance read by T1 at step 2?
A150
B100
CNULL
DUncommitted value
💡 Hint
Check the 'Data Read' column at step 2 in the execution_table.
At which step does T1 see the updated balance of 150?
AStep 4
BStep 5
CStep 6
DStep 7
💡 Hint
Look for the step where T1 reads balance after T2 commits in the execution_table.
If T2 did not commit at step 5, what would T1 read at step 6?
A100
BNULL
C150
DUncommitted 150
💡 Hint
Read Committed only shows committed data; uncommitted changes are invisible (see key_moments).
Concept Snapshot
Read Committed isolation means:
- Each query sees only data committed before it starts.
- Changes committed by other transactions between queries become visible.
- Uncommitted changes are never visible.
- Prevents dirty reads but allows non-repeatable reads.
- Default isolation level in PostgreSQL.
Full Transcript
This visual trace shows how Read Committed isolation works in PostgreSQL. Transaction T1 starts and reads a balance of 100. Meanwhile, T2 starts, updates the balance to 150, and commits. When T1 reads again, it sees the updated balance 150 because the change is now committed. This demonstrates that each query in Read Committed sees only committed data at its start, so T1 does not see uncommitted changes but can see committed changes made by others between its queries.