The default transaction isolation level is SERIALIZABLE, which is the strictest level of SQL transaction isolation. This level emulates transactions executed one after another, serially, rather than concurrently. It holds locks, and blocks write operations. For normal query operations, you can gain a significant performance improvement by using Snapshot Isolation.
Syntax
SET SESSION CHARACTERISTICS AS TRANSACTION
ISOLATION LEVEL SERIALIZABLE
SELECT ...
Semantics
When a transaction's isolation level is SERIALIZABLE, a non-historical SELECT query sees:
It cannot see data committed during the current transaction by other transactions. To illustrate, two separate transactions are shown executing concurrently.
Transaction A |
Transaction B |
SELECT C1 FROM T1; C1 -- (0 rows) |
SELECT C1 FROM T1; C1 -- (0 rows) |
INSERT INTO T1 (C1) VALUES (1); |
|
SELECT C1 FROM T1; C1 -- 1 (1 rows) |
SELECT C1 FROM T1; C1 -- (0 rows) |
COMMIT; |
|
SELECT C1 FROM T1; C1 -- 1 (1 rows) |
SELECT C1 FROM T1; C1 -- 1 (1 rows) |
Only the owner of the transaction that executed the INSERT statement (A) can see the uncommited data.