What transaction isolation levels are supported in PostgreSQL?
sobes.tech AI
Answer from AI
PostgreSQL supports four standard transaction isolation levels defined in the SQL standard:
-
Read Uncommitted — the lowest isolation level, allows reading uncommitted data (dirty reads). In PostgreSQL, it effectively behaves like Read Committed.
-
Read Committed — the default in PostgreSQL. A transaction sees only data committed before each individual read operation. Non-repeatable reads are possible.
-
Repeatable Read — a transaction sees data as it was at the start of the transaction, preventing non-repeatable reads but allowing phantom reads.
-
Serializable — the strictest level, provides full transaction isolation, preventing phantom reads and other anomalies, simulating sequential transaction execution.
Example of setting the isolation level in SQL:
BEGIN TRANSACTION ISOLATION LEVEL SERIALIZABLE;
-- operations
COMMIT;