Supported Versions: Current (17) / 16 / 15 / 14 / 13
Development Versions: devel
Unsupported versions: 12 / 11 / 10 / 9.6 / 9.5 / 9.4 / 9.3 / 9.2 / 9.1 / 9.0 / 8.4 / 8.3 / 8.2 / 8.1 / 8.0 / 7.4 / 7.3 / 7.2 / 7.1
This documentation is for an unsupported version of PostgreSQL.
You may want to view the same page for the current version, or one of the other supported versions listed above instead.

SET TRANSACTION

Name

SET TRANSACTION -- Set the characteristics of the current SQL-transaction

Synopsis

SET TRANSACTION ISOLATION LEVEL { READ COMMITTED | SERIALIZABLE }
SET SESSION CHARACTERISTICS AS TRANSACTION ISOLATION LEVEL { READ COMMITTED | SERIALIZABLE }
  

Description

This command sets the transaction isolation level. The SET TRANSACTION command sets the characteristics for the current SQL-transaction. It has no effect on any subsequent transactions. This command cannot be used after the first DML statement (SELECT, INSERT, DELETE, UPDATE, FETCH, COPY) of a transaction has been executed. SET SESSION CHARACTERISTICS sets the default transaction isolation level for each transaction for a session. SET TRANSACTION can override it for an individual transaction.

The isolation level of a transaction determines what data the transaction can see when other transactions are running concurrently.

READ COMMITTED

A statement can only see rows committed before it began. This is the default.

SERIALIZABLE

The current transaction can only see rows committed before first DML statement was executed in this transaction.

Tip: Intuitively, serializable means that two concurrent transactions will leave the database in the same state as if the two has been executed strictly after one another in either order.

Compatibility

SQL92, SQL99

SERIALIZABLE is the default level in SQL. Postgres does not provide the isolation levels READ UNCOMMITTED and REPEATABLE READ. Because of multi-version concurrency control, the serializable level is not truly serializable. See the User's Guide for details.

In SQL there are two other transaction characteristics that can be set with these commands: whether the transaction is read-only and the size of the diagnostics area. Neither of these concepts are supported in Postgres.