Understanding Read Committed Isolation in PostgreSQL
Transaction isolation levels play a crucial role in balancing consistency and performance. Over the course of next few articles, I would be touching on nuggets which could be critical decisions in this direction. PostgreSQL offers several isolation levels. Among them, Read Committed is the default and widely used.
What Is Read Committed?
Concurrency
Example
BEGIN; SELECT Balance FROM AccountHolder WHERE AccountHolderId = 123;
-- Reads the original balance UPDATE AccountHolder SET Balance = 150
WHERE AccountHolderId = 123; -- Uncommitted update -- ... other operations ... COMMIT;
Transaction B:
领英推荐
BEGIN; SELECT Balance FROM AccountHolder WHERE AccountHolderId = 123;
-- Reads the original balance (not the uncommitted value)
-- ... other operations ... COMMIT;
Transaction B will only see the original balance (before Transaction A’s update) and not the uncommitted value.
BEGIN; SELECT Balance FROM AccountHolder WHERE AccountHolderId = 123;
-- Reads the updated balance (150)
-- ... other operations ... COMMIT;
This behavior allows a transaction to observe its own changes before committing them.
Use Cases
Conclusion
For more in-depth information, explore the official PostgreSQL documentation.
Feel free to share this article with your network! ????