{
    "content": [
        {
            "type": "text",
            "text": "# SET_TRANSACTION(7) (man)\n\n**Summary:** SETTRANSACTION - set the characteristics of the current transaction\n\n**Synopsis:** SET TRANSACTION transactionmode [, ...]\nSET TRANSACTION SNAPSHOT snapshotid\nSET SESSION CHARACTERISTICS AS TRANSACTION transactionmode [, ...]\nwhere transactionmode is one of:\nISOLATION LEVEL { SERIALIZABLE | REPEATABLE READ | READ COMMITTED | READ UNCOMMITTED }\nREAD WRITE | READ ONLY\n[ NOT ] DEFERRABLE\n\n## Examples\n\n- `To begin a new transaction with the same snapshot as an already existing transaction, first`\n- `export the snapshot from the existing transaction. That will return the snapshot identifier,`\n- `for example:`\n- `BEGIN TRANSACTION ISOLATION LEVEL REPEATABLE READ;`\n- `SELECT pgexportsnapshot();`\n- `pgexportsnapshot`\n- `---------------------`\n- `00000003-0000001B-1`\n- `(1 row)`\n- `Then give the snapshot identifier in a SET TRANSACTION SNAPSHOT command at the beginning of`\n- `the newly opened transaction:`\n- `BEGIN TRANSACTION ISOLATION LEVEL REPEATABLE READ;`\n- `SET TRANSACTION SNAPSHOT '00000003-0000001B-1';`\n\n## Section Outline\n\n- **NAME** (2 lines)\n- **SYNOPSIS** (10 lines)\n- **DESCRIPTION** (61 lines)\n- **NOTES** (19 lines)\n- **EXAMPLES** (17 lines)\n- **COMPATIBILITY** (16 lines)\n\n## Full Content\n\n### NAME\n\nSETTRANSACTION - set the characteristics of the current transaction\n\n### SYNOPSIS\n\nSET TRANSACTION transactionmode [, ...]\nSET TRANSACTION SNAPSHOT snapshotid\nSET SESSION CHARACTERISTICS AS TRANSACTION transactionmode [, ...]\n\nwhere transactionmode is one of:\n\nISOLATION LEVEL { SERIALIZABLE | REPEATABLE READ | READ COMMITTED | READ UNCOMMITTED }\nREAD WRITE | READ ONLY\n[ NOT ] DEFERRABLE\n\n### DESCRIPTION\n\nThe SET TRANSACTION command sets the characteristics of the current transaction. It has no\neffect on any subsequent transactions.  SET SESSION CHARACTERISTICS sets the default\ntransaction characteristics for subsequent transactions of a session. These defaults can be\noverridden by SET TRANSACTION for an individual transaction.\n\nThe available transaction characteristics are the transaction isolation level, the\ntransaction access mode (read/write or read-only), and the deferrable mode. In addition, a\nsnapshot can be selected, though only for the current transaction, not as a session default.\n\nThe isolation level of a transaction determines what data the transaction can see when other\ntransactions are running concurrently:\n\nREAD COMMITTED\nA statement can only see rows committed before it began. This is the default.\n\nREPEATABLE READ\nAll statements of the current transaction can only see rows committed before the first\nquery or data-modification statement was executed in this transaction.\n\nSERIALIZABLE\nAll statements of the current transaction can only see rows committed before the first\nquery or data-modification statement was executed in this transaction. If a pattern of\nreads and writes among concurrent serializable transactions would create a situation\nwhich could not have occurred for any serial (one-at-a-time) execution of those\ntransactions, one of them will be rolled back with a serializationfailure error.\nThe SQL standard defines one additional level, READ UNCOMMITTED. In PostgreSQL READ\nUNCOMMITTED is treated as READ COMMITTED.\n\nThe transaction isolation level cannot be changed after the first query or data-modification\nstatement (SELECT, INSERT, DELETE, UPDATE, FETCH, or COPY) of a transaction has been\nexecuted. See Chapter 13 for more information about transaction isolation and concurrency\ncontrol.\n\nThe transaction access mode determines whether the transaction is read/write or read-only.\nRead/write is the default. When a transaction is read-only, the following SQL commands are\ndisallowed: INSERT, UPDATE, DELETE, and COPY FROM if the table they would write to is not a\ntemporary table; all CREATE, ALTER, and DROP commands; COMMENT, GRANT, REVOKE, TRUNCATE; and\nEXPLAIN ANALYZE and EXECUTE if the command they would execute is among those listed. This is\na high-level notion of read-only that does not prevent all writes to disk.\n\nThe DEFERRABLE transaction property has no effect unless the transaction is also SERIALIZABLE\nand READ ONLY. When all three of these properties are selected for a transaction, the\ntransaction may block when first acquiring its snapshot, after which it is able to run\nwithout the normal overhead of a SERIALIZABLE transaction and without any risk of\ncontributing to or being canceled by a serialization failure. This mode is well suited for\nlong-running reports or backups.\n\nThe SET TRANSACTION SNAPSHOT command allows a new transaction to run with the same snapshot\nas an existing transaction. The pre-existing transaction must have exported its snapshot with\nthe pgexportsnapshot function (see Section 9.27.5). That function returns a snapshot\nidentifier, which must be given to SET TRANSACTION SNAPSHOT to specify which snapshot is to\nbe imported. The identifier must be written as a string literal in this command, for example\n'00000003-0000001B-1'.  SET TRANSACTION SNAPSHOT can only be executed at the start of a\ntransaction, before the first query or data-modification statement (SELECT, INSERT, DELETE,\nUPDATE, FETCH, or COPY) of the transaction. Furthermore, the transaction must already be set\nto SERIALIZABLE or REPEATABLE READ isolation level (otherwise, the snapshot would be\ndiscarded immediately, since READ COMMITTED mode takes a new snapshot for each command). If\nthe importing transaction uses SERIALIZABLE isolation level, then the transaction that\nexported the snapshot must also use that isolation level. Also, a non-read-only serializable\ntransaction cannot import a snapshot from a read-only transaction.\n\n### NOTES\n\nIf SET TRANSACTION is executed without a prior START TRANSACTION or BEGIN, it emits a warning\nand otherwise has no effect.\n\nIt is possible to dispense with SET TRANSACTION by instead specifying the desired\ntransactionmodes in BEGIN or START TRANSACTION. But that option is not available for SET\nTRANSACTION SNAPSHOT.\n\nThe session default transaction modes can also be set or examined via the configuration\nparameters defaulttransactionisolation, defaulttransactionreadonly, and\ndefaulttransactiondeferrable. (In fact SET SESSION CHARACTERISTICS is just a verbose\nequivalent for setting these variables with SET.) This means the defaults can be set in the\nconfiguration file, via ALTER DATABASE, etc. Consult Chapter 20 for more information.\n\nThe current transaction's modes can similarly be set or examined via the configuration\nparameters transactionisolation, transactionreadonly, and transactiondeferrable. Setting\none of these parameters acts the same as the corresponding SET TRANSACTION option, with the\nsame restrictions on when it can be done. However, these parameters cannot be set in the\nconfiguration file, or from any source other than live SQL.\n\n### EXAMPLES\n\nTo begin a new transaction with the same snapshot as an already existing transaction, first\nexport the snapshot from the existing transaction. That will return the snapshot identifier,\nfor example:\n\nBEGIN TRANSACTION ISOLATION LEVEL REPEATABLE READ;\nSELECT pgexportsnapshot();\npgexportsnapshot\n---------------------\n00000003-0000001B-1\n(1 row)\n\nThen give the snapshot identifier in a SET TRANSACTION SNAPSHOT command at the beginning of\nthe newly opened transaction:\n\nBEGIN TRANSACTION ISOLATION LEVEL REPEATABLE READ;\nSET TRANSACTION SNAPSHOT '00000003-0000001B-1';\n\n### COMPATIBILITY\n\nThese commands are defined in the SQL standard, except for the DEFERRABLE transaction mode\nand the SET TRANSACTION SNAPSHOT form, which are PostgreSQL extensions.\n\nSERIALIZABLE is the default transaction isolation level in the standard. In PostgreSQL the\ndefault is ordinarily READ COMMITTED, but you can change it as mentioned above.\n\nIn the SQL standard, there is one other transaction characteristic that can be set with these\ncommands: the size of the diagnostics area. This concept is specific to embedded SQL, and\ntherefore is not implemented in the PostgreSQL server.\n\nThe SQL standard requires commas between successive transactionmodes, but for historical\nreasons PostgreSQL allows the commas to be omitted.\n\n\n\nPostgreSQL 14.23                                2026                              SET TRANSACTION(7)\n\n"
        }
    ],
    "structuredContent": {
        "command": "SET_TRANSACTION",
        "section": "7",
        "mode": "man",
        "summary": "SETTRANSACTION - set the characteristics of the current transaction",
        "synopsis": "SET TRANSACTION transactionmode [, ...]\nSET TRANSACTION SNAPSHOT snapshotid\nSET SESSION CHARACTERISTICS AS TRANSACTION transactionmode [, ...]\nwhere transactionmode is one of:\nISOLATION LEVEL { SERIALIZABLE | REPEATABLE READ | READ COMMITTED | READ UNCOMMITTED }\nREAD WRITE | READ ONLY\n[ NOT ] DEFERRABLE",
        "flags": [],
        "examples": [
            "To begin a new transaction with the same snapshot as an already existing transaction, first",
            "export the snapshot from the existing transaction. That will return the snapshot identifier,",
            "for example:",
            "BEGIN TRANSACTION ISOLATION LEVEL REPEATABLE READ;",
            "SELECT pgexportsnapshot();",
            "pgexportsnapshot",
            "---------------------",
            "00000003-0000001B-1",
            "(1 row)",
            "Then give the snapshot identifier in a SET TRANSACTION SNAPSHOT command at the beginning of",
            "the newly opened transaction:",
            "BEGIN TRANSACTION ISOLATION LEVEL REPEATABLE READ;",
            "SET TRANSACTION SNAPSHOT '00000003-0000001B-1';"
        ],
        "see_also": [],
        "section_outline": [
            {
                "name": "NAME",
                "lines": 2,
                "subsections": []
            },
            {
                "name": "SYNOPSIS",
                "lines": 10,
                "subsections": []
            },
            {
                "name": "DESCRIPTION",
                "lines": 61,
                "subsections": []
            },
            {
                "name": "NOTES",
                "lines": 19,
                "subsections": []
            },
            {
                "name": "EXAMPLES",
                "lines": 17,
                "subsections": []
            },
            {
                "name": "COMPATIBILITY",
                "lines": 16,
                "subsections": []
            }
        ]
    }
}