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 :
When a transaction reads the changes made by another uncommitted transaction
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
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 Level||Dirty Read||Nonrepeatable Read||Phantom Read||Serialization Anomaly|
|Read uncommitted||Allowed, but not in PG||Possible||Possible||Possible|
|Read committed||Not possible||Possible||Possible||Possible|
|Repeatable read||Not possible||Not possible||Allowed, but not in PG||Possible|
|Serializable||Not possible||Not possible||Not possible||Not possible|