Interview Questions PostgreSQL Interview Questions Technologies

Transaction Isolation in PostgreSQL

PostgreSQL is fully ACID compliant and implements transactions isolation so that your application’s concurrency can be dealt with gracefully.

Transaction isolation level in PostgreSQL, can be one of:

Allows a transaction to see uncommitted changes made by other transactions
Allows a transaction to see committed changes made by other transactions
Ensures consistent SELECT output for each transaction
-SERIALIZABLE (strictest level available)
Completely isolates the effects of a transaction from others(Phantom read, non-repeatable read, dirty read – NOT POSSIBLE)

Default level for PostgreSQL – READ COMMITTED

The phenomena which are prohibited at various levels are :
Transaction Isolation Problems are :

-“Dirty” read
When a transaction reads the changes made by another uncommitted transaction
-Non-repeatable read
When changes from another committed transaction cause a prior read operation to be non-repeatable
-Phantom read (or phantom row)
A row that appears but was not previously visible within the same transaction
-Serialization anomaly
The result of successfully committing a group of transactions is inconsistent with all possible orderings of running those transactions one at a time.

To set the transaction isolation level of a transaction, use the command SET TRANSACTION.


  • Both non-repeatable and phantom reads have to do with data modification operations from a different transaction, which were committed after your transaction began, and then read by your transaction
  • Non-repeatable reads are when your transaction reads committed UPDATES from another transaction. The same row now has different values than it did when your transaction began.
  • Phantom reads are similar but when reading from committed INSERTS and/or DELETES from another transaction. There are new rows or rows that have disappeared since you began the transaction.
  • Dirty reads are similar to non-repeatable and phantom reads, but relate to reading UNCOMMITTED data, and occur when an UPDATE, INSERT, or DELETE from another transaction is read, and the other transaction has NOT yet committed the data. It is reading “in progress” data, which may not be complete, and may never actually be committed.
  • The Serializable isolation level guarantees that concurrent transactions run as they would if you would run sequentially one by one in order.

Isolation LevelDirty ReadNonrepeatable ReadPhantom ReadSerialization Anomaly
Read uncommittedAllowed, but not in PGPossiblePossiblePossible
Read committedNot possiblePossiblePossiblePossible
Repeatable readNot possibleNot possibleAllowed, but not in PGPossible
SerializableNot possibleNot possibleNot possibleNot possible

Check here, more about Transaction Isolation

Comments Rating 0 (0 reviews)

About the author


Add Comment

Click here to post a comment