

Setting one of these parameters acts the same as the corresponding SET TRANSACTION option, with the same restrictions on when it can be done. The current transaction's modes can similarly be set or examined via the configuration parameters transaction_isolation, transaction_read_only, and transaction_deferrable. (In fact SET SESSION CHARACTERISTICS is just a verbose equivalent for setting these variables with SET.) This means the defaults can be set in the configuration file, via ALTER DATABASE, etc. The session default transaction modes can also be set or examined via the configuration parameters default_transaction_isolation, default_transaction_read_only, and default_transaction_deferrable. But that option is not available for SET TRANSACTION SNAPSHOT. It is possible to dispense with SET TRANSACTION by instead specifying the desired transaction_modes in BEGIN or START TRANSACTION. If SET TRANSACTION is executed without a prior START TRANSACTION or BEGIN, it emits a warning and otherwise has no effect. Also, a non-read-only serializable transaction cannot import a snapshot from a read-only transaction. If the importing transaction uses SERIALIZABLE isolation level, then the transaction that exported the snapshot must also use that isolation level. Furthermore, the transaction must already be set to SERIALIZABLE or REPEATABLE READ isolation level (otherwise, the snapshot would be discarded immediately, since READ COMMITTED mode takes a new snapshot for each command). SET TRANSACTION SNAPSHOT can only be executed at the start of a transaction, before the first query or data-modification statement ( SELECT, INSERT, DELETE, UPDATE, MERGE, FETCH, or COPY) of the transaction. The identifier must be written as a string literal in this command, for example '00000003-0000001B-1'. That function returns a snapshot identifier, which must be given to SET TRANSACTION SNAPSHOT to specify which snapshot is to be imported. The pre-existing transaction must have exported its snapshot with the pg_export_snapshot function (see Section 9.27.5). The SET TRANSACTION SNAPSHOT command allows a new transaction to run with the same snapshot as an existing transaction. This mode is well suited for long-running reports or backups. When all three of these properties are selected for a transaction, the transaction may block when first acquiring its snapshot, after which it is able to run without the normal overhead of a SERIALIZABLE transaction and without any risk of contributing to or being canceled by a serialization failure. The DEFERRABLE transaction property has no effect unless the transaction is also SERIALIZABLE and READ ONLY. This is a high-level notion of read-only that does not prevent all writes to disk. When a transaction is read-only, the following SQL commands are disallowed: INSERT, UPDATE, DELETE, MERGE, and COPY FROM if the table they would write to is not a temporary table all CREATE, ALTER, and DROP commands COMMENT, GRANT, REVOKE, TRUNCATE and EXPLAIN ANALYZE and EXECUTE if the command they would execute is among those listed. The transaction access mode determines whether the transaction is read/write or read-only. See Chapter 13 for more information about transaction isolation and concurrency control.

The transaction isolation level cannot be changed after the first query or data-modification statement ( SELECT, INSERT, DELETE, UPDATE, MERGE, FETCH, or COPY) of a transaction has been executed.


In PostgreSQL READ UNCOMMITTED is treated as READ COMMITTED. The SQL standard defines one additional level, READ UNCOMMITTED.
Read committed isolation serial#
If a pattern of reads and writes among concurrent serializable transactions would create a situation which could not have occurred for any serial (one-at-a-time) execution of those transactions, one of them will be rolled back with a serialization_failure error. SERIALIZABLEĪll statements of the current transaction can only see rows committed before the first query or data-modification statement was executed in this transaction. REPEATABLE READĪll statements of the current transaction can only see rows committed before the first query or data-modification statement was executed in this transaction. A statement can only see rows committed before it began.
