Sobes.tech
Junior — Middle

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:

  1. Read Uncommitted — the lowest isolation level, allows reading uncommitted data (dirty reads). In PostgreSQL, it effectively behaves like Read Committed.

  2. Read Committed — the default in PostgreSQL. A transaction sees only data committed before each individual read operation. Non-repeatable reads are possible.

  3. Repeatable Read — a transaction sees data as it was at the start of the transaction, preventing non-repeatable reads but allowing phantom reads.

  4. 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;