SET TRANSACTION
Description
Sets the transaction characteristics. Transaction characteristics include transaction isolation level and transaction access mode (read/write or read-only). You can set the current transaction characteristics using LOCAL or the default transaction characteristics of a session using SESSION.
Precautions
The current transaction characteristics must be set in a transaction, that is, START TRANSACTION or BEGIN must be executed before SET TRANSACTION is executed. Otherwise, the setting does not take effect.
Syntax
1 2 3 |
{ SET [ LOCAL ] TRANSACTION|SET SESSION CHARACTERISTICS AS TRANSACTION } { ISOLATION LEVEL { READ COMMITTED | READ UNCOMMITTED | SERIALIZABLE | REPEATABLE READ } | { READ WRITE | READ ONLY } } [, ...] |
Parameters
- LOCAL
Specifies that the specified statement takes effect only for the current transaction.
- SESSION
Specifies that the specified parameters take effect for the current session.
- ISOLATION_LEVEL_CLAUSE
Specifies the transaction isolation level that determines the data that a transaction can view if other concurrent transactions exist.
- The isolation level of a transaction cannot be reset after the first clause (INSERT, DELETE, UPDATE, FETCH, or COPY) for modifying data is executed in the transaction.
Value range:
- READ COMMITTED: Only committed data can be read. It is the default value.
- READ UNCOMMITTED: Uncommitted data is probably read. This isolation level is provided to handle CN breakdown emergencies. On this isolation level, you are advised to only read data to prevent inconsistency.
- REPEATABLE READ: Only the data committed before transaction start is read. Uncommitted data or data committed in other concurrent transactions cannot be read.
- SERIALIZABLE: Currently, this isolation level is not supported in GaussDB. It is equivalent to REPEATABLE READ.
- READ WRITE | READ ONLY
Specifies the transaction access mode (read/write or read only).
The access mode of the default transaction feature of the session can be set only when the database is started or by sending the HUP signal.
Examples
1 2 3 4 |
-- Start a transaction and set its isolation level to READ COMMITTED and access mode to READ ONLY. openGauss=# START TRANSACTION; openGauss=# SET LOCAL TRANSACTION ISOLATION LEVEL READ COMMITTED READ ONLY; openGauss=# COMMIT; |
Feedback
Was this page helpful?
Provide feedbackThank you very much for your feedback. We will continue working to improve the documentation.See the reply and handling status in My Cloud VOC.
For any further questions, feel free to contact us through the chatbot.
Chatbot