{"Entry":{"collection":"sql","key":"set-transaction","name":"SET TRANSACTION","aliases":["set-transaction"],"metadata":{"aliases":["set-transaction"],"changed_in":["7.4","8.0","9.0","9.1","9.2"],"changes":[{"from":"7.0","purpose_changed":false,"renamed":null,"sections":{"added":[],"changed":[],"removed":[]},"status":"added","synopsis":null,"to":"7.1"},{"from":"7.1","purpose_changed":true,"renamed":null,"sections":{"added":["notes"],"changed":["description","compatibility"],"removed":[]},"status":"changed","synopsis":null,"to":"7.2"},{"from":"7.2","purpose_changed":false,"renamed":null,"sections":{"added":[],"changed":["compatibility"],"removed":[]},"status":"changed","synopsis":null,"to":"7.3"},{"from":"7.3","purpose_changed":false,"renamed":null,"sections":{"added":[],"changed":["description","notes","compatibility"],"removed":[]},"status":"changed","synopsis":{"added":["[ ISOLATION LEVEL { READ COMMITTED | SERIALIZABLE } ] [ READ WRITE | READ ONLY ]","[ ISOLATION LEVEL { READ COMMITTED | SERIALIZABLE } ] [ READ WRITE | READ ONLY ]"],"removed":[]},"to":"7.4"},{"from":"7.4","purpose_changed":false,"renamed":null,"sections":{"added":[],"changed":["description","notes","compatibility"],"removed":[]},"status":"changed","synopsis":{"added":["SET TRANSACTION transaction_mode [, ...]","SET SESSION CHARACTERISTICS AS TRANSACTION transaction_mode [, ...]","where transaction_mode is one of:","ISOLATION LEVEL { SERIALIZABLE | REPEATABLE READ | READ COMMITTED | READ UNCOMMITTED }"],"removed":["[ ISOLATION LEVEL { READ COMMITTED | SERIALIZABLE } ] [ READ WRITE | READ ONLY ]","[ ISOLATION LEVEL { READ COMMITTED | SERIALIZABLE } ] [ READ WRITE | READ ONLY ]"]},"to":"8.0"},{"from":"8.0","purpose_changed":false,"renamed":null,"sections":{"added":[],"changed":["notes"],"removed":[]},"status":"changed","synopsis":null,"to":"8.1"},{"from":"8.2","purpose_changed":false,"renamed":null,"sections":{"added":[],"changed":["description","notes","compatibility"],"removed":[]},"status":"changed","synopsis":null,"to":"8.3"},{"from":"8.4","purpose_changed":false,"renamed":null,"sections":{"added":[],"changed":[],"removed":[]},"status":"changed","synopsis":{"added":[],"removed":["where transaction_mode is one of:"]},"to":"9.0"},{"from":"9.0","purpose_changed":false,"renamed":null,"sections":{"added":[],"changed":["description","notes","compatibility"],"removed":[]},"status":"changed","synopsis":{"added":["[ NOT ] DEFERRABLE"],"removed":[]},"to":"9.1"},{"from":"9.1","purpose_changed":false,"renamed":null,"sections":{"added":["examples"],"changed":["description","notes","compatibility"],"removed":[]},"status":"changed","synopsis":{"added":["SET TRANSACTION SNAPSHOT snapshot_id"],"removed":[]},"to":"9.2"},{"from":"9.3","purpose_changed":false,"renamed":null,"sections":{"added":[],"changed":["notes"],"removed":[]},"status":"changed","synopsis":null,"to":"9.4"},{"from":"9.5","purpose_changed":false,"renamed":null,"sections":{"added":[],"changed":["notes"],"removed":[]},"status":"changed","synopsis":null,"to":"9.6"},{"from":"9.6","purpose_changed":false,"renamed":null,"sections":{"added":[],"changed":["description","examples"],"removed":[]},"status":"changed","synopsis":null,"to":"10"},{"from":"12","purpose_changed":false,"renamed":null,"sections":{"added":[],"changed":["description"],"removed":[]},"status":"changed","synopsis":null,"to":"13"},{"from":"13","purpose_changed":false,"renamed":null,"sections":{"added":[],"changed":["notes"],"removed":[]},"status":"changed","synopsis":null,"to":"14"},{"from":"14","purpose_changed":false,"renamed":null,"sections":{"added":[],"changed":["description"],"removed":[]},"status":"changed","synopsis":null,"to":"15"},{"from":"16","purpose_changed":false,"renamed":null,"sections":{"added":[],"changed":["description","notes"],"removed":[]},"status":"changed","synopsis":null,"to":"17"},{"from":"18","purpose_changed":false,"renamed":null,"sections":{"added":[],"changed":["description"],"removed":[]},"status":"changed","synopsis":null,"to":"19"}],"content_hash":"0f48dc969a916b627aead44a5be60c01fa277f90e9fe34e66f97816a7168a179","editorial":{},"first_version":"7.1","group":"transaction","imported_at":"2026-09-27T17:57:27.341937+08:00","last_version":"20","name":"SET TRANSACTION","object":"TRANSACTION","position":13013,"present_in":["7.1","7.2","7.3","7.4","8.0","8.1","8.2","8.3","8.4","9.0","9.1","9.2","9.3","9.4","9.5","9.6","10","11","12","13","14","15","16","17","18","19","20"],"purpose":"set the characteristics of the current transaction","purpose_zh":"","related":[],"slug":"set-transaction","source_rev":"b7bd9cda","synopsis":"SET TRANSACTION transaction_mode [, ...]\nSET TRANSACTION SNAPSHOT snapshot_id\nSET SESSION CHARACTERISTICS AS TRANSACTION transaction_mode [, ...]\n\nwhere transaction_mode is one of:\n\nISOLATION LEVEL { SERIALIZABLE | REPEATABLE READ | READ COMMITTED | READ UNCOMMITTED }\nREAD WRITE | READ ONLY\n[ NOT ] DEFERRABLE","verb":"SET"}},"Definition":{"Collection":"sql","Key":"set-transaction","SourceDatabase":"center","Version":"18","SourceTable":"sqlcmd","SourceKey":"set-transaction","SourceRevision":"b7bd9cda","Facts":{"anchor":"SQL-SET-TRANSACTION","file":"sql-set-transaction.html","lang":"en","name":"SET TRANSACTION","purpose":"set the characteristics of the current transaction","purpose_zh":"","related":[],"sections":[{"html":"\u003cp\u003eThe \u003ccode class=\"command\"\u003eSET TRANSACTION\u003c/code\u003e command sets the characteristics of the current transaction. It has no effect on any subsequent transactions. \u003ccode class=\"command\"\u003eSET SESSION CHARACTERISTICS\u003c/code\u003e sets the default transaction characteristics for subsequent transactions of a session. These defaults can be overridden by \u003ccode class=\"command\"\u003eSET TRANSACTION\u003c/code\u003e for an individual transaction.\u003c/p\u003e\u003cp\u003eThe available transaction characteristics are the transaction isolation level, the transaction access mode (read/write or read-only), and the deferrable mode. In addition, a snapshot can be selected, though only for the current transaction, not as a session default.\u003c/p\u003e\u003cp\u003eThe isolation level of a transaction determines what data the transaction can see when other transactions are running concurrently:\u003c/p\u003e\u003cdiv class=\"variablelist\"\u003e\u003cdl class=\"variablelist\"\u003e\u003cdt\u003e\u003cspan class=\"term\"\u003e\u003ccode class=\"literal\"\u003eREAD COMMITTED\u003c/code\u003e\u003c/span\u003e\u003c/dt\u003e\u003cdd\u003e\u003cp\u003eA statement can only see rows committed before it began. This is the default.\u003c/p\u003e\u003c/dd\u003e\u003cdt\u003e\u003cspan class=\"term\"\u003e\u003ccode class=\"literal\"\u003eREPEATABLE READ\u003c/code\u003e\u003c/span\u003e\u003c/dt\u003e\u003cdd\u003e\u003cp\u003eAll statements of the current transaction can only see rows committed before the first query or data-modification statement was executed in this transaction.\u003c/p\u003e\u003c/dd\u003e\u003cdt\u003e\u003cspan class=\"term\"\u003e\u003ccode class=\"literal\"\u003eSERIALIZABLE\u003c/code\u003e\u003c/span\u003e\u003c/dt\u003e\u003cdd\u003e\u003cp\u003eAll statements of the current transaction can only see rows committed before the first query or data-modification statement was executed in this transaction. 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 \u003ccode class=\"literal\"\u003eserialization_failure\u003c/code\u003e error.\u003c/p\u003e\u003c/dd\u003e\u003c/dl\u003e\u003c/div\u003e\u003cp\u003eThe SQL standard defines one additional level, \u003ccode class=\"literal\"\u003eREAD UNCOMMITTED\u003c/code\u003e. In \u003cspan class=\"productname\"\u003ePostgreSQL\u003c/span\u003e \u003ccode class=\"literal\"\u003eREAD UNCOMMITTED\u003c/code\u003e is treated as \u003ccode class=\"literal\"\u003eREAD COMMITTED\u003c/code\u003e.\u003c/p\u003e\u003cp\u003eThe transaction isolation level cannot be changed after the first query or data-modification statement (\u003ccode class=\"command\"\u003eSELECT\u003c/code\u003e, \u003ccode class=\"command\"\u003eINSERT\u003c/code\u003e, \u003ccode class=\"command\"\u003eDELETE\u003c/code\u003e, \u003ccode class=\"command\"\u003eUPDATE\u003c/code\u003e, \u003ccode class=\"command\"\u003eMERGE\u003c/code\u003e, \u003ccode class=\"command\"\u003eFETCH\u003c/code\u003e, or \u003ccode class=\"command\"\u003eCOPY\u003c/code\u003e) of a transaction has been executed. See \u003ca href=\"/docs/18/mvcc.html\" title=\"Chapter 13. Concurrency Control\"\u003eChapter 13\u003c/a\u003e for more information about transaction isolation and concurrency control.\u003c/p\u003e\u003cp\u003eThe transaction access mode determines whether the transaction is read/write or read-only. Read/write is the default. When a transaction is read-only, the following SQL commands are disallowed: \u003ccode class=\"command\"\u003eINSERT\u003c/code\u003e, \u003ccode class=\"command\"\u003eUPDATE\u003c/code\u003e, \u003ccode class=\"command\"\u003eDELETE\u003c/code\u003e, \u003ccode class=\"command\"\u003eMERGE\u003c/code\u003e, and \u003ccode class=\"command\"\u003eCOPY FROM\u003c/code\u003e if the table they would write to is not a temporary table; all \u003ccode class=\"literal\"\u003eCREATE\u003c/code\u003e, \u003ccode class=\"literal\"\u003eALTER\u003c/code\u003e, and \u003ccode class=\"literal\"\u003eDROP\u003c/code\u003e commands; \u003ccode class=\"literal\"\u003eCOMMENT\u003c/code\u003e, \u003ccode class=\"literal\"\u003eGRANT\u003c/code\u003e, \u003ccode class=\"literal\"\u003eREVOKE\u003c/code\u003e, \u003ccode class=\"literal\"\u003eTRUNCATE\u003c/code\u003e; and \u003ccode class=\"literal\"\u003eEXPLAIN ANALYZE\u003c/code\u003e and \u003ccode class=\"literal\"\u003eEXECUTE\u003c/code\u003e if the command they would execute is among those listed. This is a high-level notion of read-only that does not prevent all writes to disk.\u003c/p\u003e\u003cp\u003eThe \u003ccode class=\"literal\"\u003eDEFERRABLE\u003c/code\u003e transaction property has no effect unless the transaction is also \u003ccode class=\"literal\"\u003eSERIALIZABLE\u003c/code\u003e and \u003ccode class=\"literal\"\u003eREAD ONLY\u003c/code\u003e. 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 \u003ccode class=\"literal\"\u003eSERIALIZABLE\u003c/code\u003e transaction and without any risk of contributing to or being canceled by a serialization failure. This mode is well suited for long-running reports or backups.\u003c/p\u003e\u003cp\u003eThe \u003ccode class=\"literal\"\u003eSET TRANSACTION SNAPSHOT\u003c/code\u003e command allows a new transaction to run with the same \u003cem class=\"firstterm\"\u003esnapshot\u003c/em\u003e as an existing transaction. The pre-existing transaction must have exported its snapshot with the \u003ccode class=\"literal\"\u003epg_export_snapshot\u003c/code\u003e function (see \u003ca href=\"/docs/18/functions-admin.html#FUNCTIONS-SNAPSHOT-SYNCHRONIZATION\" title=\"9.28.5. Snapshot Synchronization Functions\"\u003eSection 9.28.5\u003c/a\u003e). That function returns a snapshot identifier, which must be given to \u003ccode class=\"literal\"\u003eSET TRANSACTION SNAPSHOT\u003c/code\u003e to specify which snapshot is to be imported. The identifier must be written as a string literal in this command, for example \u003ccode class=\"literal\"\u003e'00000003-0000001B-1'\u003c/code\u003e. \u003ccode class=\"literal\"\u003eSET TRANSACTION SNAPSHOT\u003c/code\u003e can only be executed at the start of a transaction, before the first query or data-modification statement (\u003ccode class=\"command\"\u003eSELECT\u003c/code\u003e, \u003ccode class=\"command\"\u003eINSERT\u003c/code\u003e, \u003ccode class=\"command\"\u003eDELETE\u003c/code\u003e, \u003ccode class=\"command\"\u003eUPDATE\u003c/code\u003e, \u003ccode class=\"command\"\u003eMERGE\u003c/code\u003e, \u003ccode class=\"command\"\u003eFETCH\u003c/code\u003e, or \u003ccode class=\"command\"\u003eCOPY\u003c/code\u003e) of the transaction. Furthermore, the transaction must already be set to \u003ccode class=\"literal\"\u003eSERIALIZABLE\u003c/code\u003e or \u003ccode class=\"literal\"\u003eREPEATABLE READ\u003c/code\u003e isolation level (otherwise, the snapshot would be discarded immediately, since \u003ccode class=\"literal\"\u003eREAD COMMITTED\u003c/code\u003e mode takes a new snapshot for each command). If the importing transaction uses \u003ccode class=\"literal\"\u003eSERIALIZABLE\u003c/code\u003e isolation level, then the transaction that exported the snapshot must also use that isolation level. Also, a non-read-only serializable transaction cannot import a snapshot from a read-only transaction.\u003c/p\u003e","key":"description","title":"Description"},{"html":"\u003cp\u003eIf \u003ccode class=\"command\"\u003eSET TRANSACTION\u003c/code\u003e is executed without a prior \u003ccode class=\"command\"\u003eSTART TRANSACTION\u003c/code\u003e or \u003ccode class=\"command\"\u003eBEGIN\u003c/code\u003e, it emits a warning and otherwise has no effect.\u003c/p\u003e\u003cp\u003eIt is possible to dispense with \u003ccode class=\"command\"\u003eSET TRANSACTION\u003c/code\u003e by instead specifying the desired \u003cem class=\"replaceable\"\u003e\u003ccode\u003etransaction_modes\u003c/code\u003e\u003c/em\u003e in \u003ccode class=\"command\"\u003eBEGIN\u003c/code\u003e or \u003ccode class=\"command\"\u003eSTART TRANSACTION\u003c/code\u003e. But that option is not available for \u003ccode class=\"command\"\u003eSET TRANSACTION SNAPSHOT\u003c/code\u003e.\u003c/p\u003e\u003cp\u003eThe session default transaction modes can also be set or examined via the configuration parameters \u003ca href=\"/docs/18/runtime-config-client.html#GUC-DEFAULT-TRANSACTION-ISOLATION\"\u003edefault_transaction_isolation\u003c/a\u003e, \u003ca href=\"/docs/18/runtime-config-client.html#GUC-DEFAULT-TRANSACTION-READ-ONLY\"\u003edefault_transaction_read_only\u003c/a\u003e, and \u003ca href=\"/docs/18/runtime-config-client.html#GUC-DEFAULT-TRANSACTION-DEFERRABLE\"\u003edefault_transaction_deferrable\u003c/a\u003e. (In fact \u003ccode class=\"command\"\u003eSET SESSION CHARACTERISTICS\u003c/code\u003e is just a verbose equivalent for setting these variables with \u003ccode class=\"command\"\u003eSET\u003c/code\u003e.) This means the defaults can be set in the configuration file, via \u003ccode class=\"command\"\u003eALTER DATABASE\u003c/code\u003e, etc. Consult \u003ca href=\"/docs/18/runtime-config.html\" title=\"Chapter 19. Server Configuration\"\u003eChapter 19\u003c/a\u003e for more information.\u003c/p\u003e\u003cp\u003eThe current transaction's modes can similarly be set or examined via the configuration parameters \u003ca href=\"/docs/18/runtime-config-client.html#GUC-TRANSACTION-ISOLATION\"\u003etransaction_isolation\u003c/a\u003e, \u003ca href=\"/docs/18/runtime-config-client.html#GUC-TRANSACTION-READ-ONLY\"\u003etransaction_read_only\u003c/a\u003e, and \u003ca href=\"/docs/18/runtime-config-client.html#GUC-TRANSACTION-DEFERRABLE\"\u003etransaction_deferrable\u003c/a\u003e. Setting one of these parameters acts the same as the corresponding \u003ccode class=\"command\"\u003eSET TRANSACTION\u003c/code\u003e option, with the same restrictions on when it can be done. However, these parameters cannot be set in the configuration file, or from any source other than live SQL.\u003c/p\u003e","key":"notes","title":"Notes"},{"html":"\u003cp\u003eTo 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:\u003c/p\u003e\u003cpre class=\"programlisting\"\u003eBEGIN TRANSACTION ISOLATION LEVEL REPEATABLE READ;\nSELECT pg_export_snapshot();\n pg_export_snapshot\n---------------------\n 00000003-0000001B-1\n(1 row)\n\u003c/pre\u003e\u003cp\u003eThen give the snapshot identifier in a \u003ccode class=\"command\"\u003eSET TRANSACTION SNAPSHOT\u003c/code\u003e command at the beginning of the newly opened transaction:\u003c/p\u003e\u003cpre class=\"programlisting\"\u003eBEGIN TRANSACTION ISOLATION LEVEL REPEATABLE READ;\nSET TRANSACTION SNAPSHOT '00000003-0000001B-1';\n\u003c/pre\u003e","key":"examples","title":"Examples"},{"html":"\u003cp\u003eThese commands are defined in the \u003cacronym\u003eSQL\u003c/acronym\u003e standard, except for the \u003ccode class=\"literal\"\u003eDEFERRABLE\u003c/code\u003e transaction mode and the \u003ccode class=\"command\"\u003eSET TRANSACTION SNAPSHOT\u003c/code\u003e form, which are \u003cspan class=\"productname\"\u003ePostgreSQL\u003c/span\u003e extensions.\u003c/p\u003e\u003cp\u003e\u003ccode class=\"literal\"\u003eSERIALIZABLE\u003c/code\u003e is the default transaction isolation level in the standard. In \u003cspan class=\"productname\"\u003ePostgreSQL\u003c/span\u003e the default is ordinarily \u003ccode class=\"literal\"\u003eREAD COMMITTED\u003c/code\u003e, but you can change it as mentioned above.\u003c/p\u003e\u003cp\u003eIn the SQL standard, there is one other transaction characteristic that can be set with these commands: the size of the diagnostics area. This concept is specific to embedded SQL, and therefore is not implemented in the \u003cspan class=\"productname\"\u003ePostgreSQL\u003c/span\u003e server.\u003c/p\u003e\u003cp\u003eThe SQL standard requires commas between successive \u003cem class=\"replaceable\"\u003e\u003ccode\u003etransaction_modes\u003c/code\u003e\u003c/em\u003e, but for historical reasons \u003cspan class=\"productname\"\u003ePostgreSQL\u003c/span\u003e allows the commas to be omitted.\u003c/p\u003e","key":"compatibility","title":"Compatibility"}],"sections_same_as":"","slug":"18","synopsis_html":"SET TRANSACTION \u003cem class=\"replaceable\"\u003e\u003ccode\u003etransaction_mode\u003c/code\u003e\u003c/em\u003e [, ...]\nSET TRANSACTION SNAPSHOT \u003cem class=\"replaceable\"\u003e\u003ccode\u003esnapshot_id\u003c/code\u003e\u003c/em\u003e\nSET SESSION CHARACTERISTICS AS TRANSACTION \u003cem class=\"replaceable\"\u003e\u003ccode\u003etransaction_mode\u003c/code\u003e\u003c/em\u003e [, ...]\n\n\u003cspan class=\"phrase\"\u003ewhere \u003cem class=\"replaceable\"\u003e\u003ccode\u003etransaction_mode\u003c/code\u003e\u003c/em\u003e is one of:\u003c/span\u003e\n\n    ISOLATION LEVEL { SERIALIZABLE | REPEATABLE READ | READ COMMITTED | READ UNCOMMITTED }\n    READ WRITE | READ ONLY\n    [ NOT ] DEFERRABLE","synopsis_text":"SET TRANSACTION transaction_mode [, ...]\nSET TRANSACTION SNAPSHOT snapshot_id\nSET SESSION CHARACTERISTICS AS TRANSACTION transaction_mode [, ...]\n\nwhere transaction_mode is one of:\n\nISOLATION LEVEL { SERIALIZABLE | REPEATABLE READ | READ COMMITTED | READ UNCOMMITTED }\nREAD WRITE | READ ONLY\n[ NOT ] DEFERRABLE"},"ManualEvidence":{},"MeasuredEvidence":{}},"Text":{"Collection":"sql","Key":"set-transaction","SourceDatabase":"pgweb","Version":"18","Locale":"zh-Hans","Title":"SET TRANSACTION","Summary":"设置当前事务的特性","BodyHTML":"\u003cpre\u003eSET TRANSACTION transaction_mode [, ...]\nSET TRANSACTION SNAPSHOT snapshot_id\nSET SESSION CHARACTERISTICS AS TRANSACTION transaction_mode [, ...]\n\n其中 transaction_mode 是下列之一：\n\nISOLATION LEVEL { SERIALIZABLE | REPEATABLE READ | READ COMMITTED | READ UNCOMMITTED }\nREAD WRITE | READ ONLY\n[ NOT ] DEFERRABLE\u003c/pre\u003e\u003csection\u003e\u003ch2\u003e描述\u003c/h2\u003e\u003cp\u003e\u003ccode\u003eSET TRANSACTION\u003c/code\u003e命令设置当前事务的特性。它对任何后续事务都没有影响。\u003ccode\u003eSET SESSION CHARACTERISTICS\u003c/code\u003e设置一个会话中后续事务的默认事务特性。对于单个事务，这些默认值可以用 \u003ccode\u003eSET TRANSACTION\u003c/code\u003e覆盖。\u003c/p\u003e\u003cp\u003e可用的事务特性是事务隔离级别、事务访问模式（读/写或只读）以及可延迟模式。此外，还可以选择一个快照，不过它只能用于当前事务，不能作为会话默认值。\u003c/p\u003e\u003cp\u003e一个事务的隔离级别决定当其他事务并发运行时该事务能看见什么数据：\u003c/p\u003e\u003cdiv\u003e\u003cdl\u003e\u003cdt\u003e\u003cspan\u003e\u003ccode\u003eREAD COMMITTED\u003c/code\u003e\u003c/span\u003e\u003c/dt\u003e\u003cdd\u003e\u003cp\u003e一条语句只能看到在它开始之前已提交的行。这是默认值。\u003c/p\u003e\u003c/dd\u003e\u003cdt\u003e\u003cspan\u003e\u003ccode\u003eREPEATABLE READ\u003c/code\u003e\u003c/span\u003e\u003c/dt\u003e\u003cdd\u003e\u003cp\u003e当前事务中的所有语句都只能看到在该事务中执行第一条查询或数据修改语句之前已提交的行。\u003c/p\u003e\u003c/dd\u003e\u003cdt\u003e\u003cspan\u003e\u003ccode\u003eSERIALIZABLE\u003c/code\u003e\u003c/span\u003e\u003c/dt\u003e\u003cdd\u003e\u003cp\u003e当前事务中的所有语句都只能看到在该事务中执行第一条查询或数据修改语句之前已提交的行。如果并发的可串行化事务之间出现某种读写模式，而这种情况不可能在这些事务的任何串行（一次执行一个）执行中发生，那么其中一个事务将以 \u003ccode\u003eserialization_failure\u003c/code\u003e错误回滚。\u003c/p\u003e\u003c/dd\u003e\u003c/dl\u003e\u003c/div\u003e\u003cp\u003eSQL 标准还定义了一个额外的级别：\u003ccode\u003eREAD UNCOMMITTED\u003c/code\u003e。在 \u003cspan\u003ePostgreSQL\u003c/span\u003e中，\u003ccode\u003eREAD UNCOMMITTED\u003c/code\u003e被视为 \u003ccode\u003eREAD COMMITTED\u003c/code\u003e。\u003c/p\u003e\u003cp\u003e在事务执行第一条查询或数据修改语句（\u003ccode\u003eSELECT\u003c/code\u003e，\u003ccode\u003eINSERT\u003c/code\u003e，\u003ccode\u003eDELETE\u003c/code\u003e，\u003ccode\u003eUPDATE\u003c/code\u003e，\u003ccode\u003eMERGE\u003c/code\u003e，\u003ccode\u003eFETCH\u003c/code\u003e，或 \u003ccode\u003eCOPY\u003c/code\u003e）之后，事务隔离级别就不能再更改。有关事务隔离和并发控制的更多信息，请参见\u003ca href=\"/docs/18/mvcc.html\" rel=\"nofollow\"\u003e第 13 章\u003c/a\u003e。\u003c/p\u003e\u003cp\u003e事务访问模式决定事务是读/写还是只读。读/写是默认值。当事务为只读时，下列 SQL 命令会被禁止：\u003ccode\u003eINSERT\u003c/code\u003e、\u003ccode\u003eUPDATE\u003c/code\u003e、\u003ccode\u003eDELETE\u003c/code\u003e、\u003ccode\u003eMERGE\u003c/code\u003e 以及 \u003ccode\u003eCOPY FROM\u003c/code\u003e，前提是它们要写入的表不是临时表；所有 \u003ccode\u003eCREATE\u003c/code\u003e、\u003ccode\u003eALTER\u003c/code\u003e 和 \u003ccode\u003eDROP\u003c/code\u003e 命令；\u003ccode\u003eCOMMENT\u003c/code\u003e、\u003ccode\u003eGRANT\u003c/code\u003e、\u003ccode\u003eREVOKE\u003c/code\u003e、\u003ccode\u003eTRUNCATE\u003c/code\u003e；以及 \u003ccode\u003eEXPLAIN ANALYZE\u003c/code\u003e 和 \u003ccode\u003eEXECUTE\u003c/code\u003e，前提是它们要执行的命令属于上述列表。这是一个较高层面的只读概念，并不会阻止所有写入磁盘的行为。\u003c/p\u003e\u003cp\u003e只有当事务同时是\u003ccode\u003eSERIALIZABLE\u003c/code\u003e和 \u003ccode\u003eREAD ONLY\u003c/code\u003e时，\u003ccode\u003eDEFERRABLE\u003c/code\u003e 事务属性才会生效。当为一个事务同时选择这三个属性时，该事务在首次获取其快照时可能会阻塞；在此之后，它便可以运行，而无需承担普通 \u003ccode\u003eSERIALIZABLE\u003c/code\u003e事务的常规开销，也不会有促成串行化失败或因串行化失败而被取消的风险。这种模式非常适合长时间运行的报表或备份。\u003c/p\u003e\u003cp\u003e\u003ccode\u003eSET TRANSACTION SNAPSHOT\u003c/code\u003e命令允许一个新事务使用与现有事务相同的\u003cem\u003e快照\u003c/em\u003e运行。已有事务必须用 \u003ccode\u003epg_export_snapshot\u003c/code\u003e函数导出其快照（参见\u003ca href=\"/docs/18/functions-admin.html#FUNCTIONS-SNAPSHOT-SYNCHRONIZATION\" rel=\"nofollow\"\u003e第 9.28.5 节\u003c/a\u003e）。该函数会返回一个快照标识符，必须将其提供给\u003ccode\u003eSET TRANSACTION SNAPSHOT\u003c/code\u003e以指定要导入的快照。该标识符在此命令中必须写成字符串字面量，例如 \u003ccode\u003e\u0026#39;00000003-0000001B-1\u0026#39;\u003c/code\u003e。\u003ccode\u003eSET TRANSACTION SNAPSHOT\u003c/code\u003e只能在事务开始时执行，也就是在事务的第一条查询或数据修改语句（\u003ccode\u003eSELECT\u003c/code\u003e、\u003ccode\u003eINSERT\u003c/code\u003e、\u003ccode\u003eDELETE\u003c/code\u003e、\u003ccode\u003eUPDATE\u003c/code\u003e、\u003ccode\u003eMERGE\u003c/code\u003e、\u003ccode\u003eFETCH\u003c/code\u003e 或 \u003ccode\u003eCOPY\u003c/code\u003e）之前。此外，事务还必须已经设置为 \u003ccode\u003eSERIALIZABLE\u003c/code\u003e 或 \u003ccode\u003eREPEATABLE READ\u003c/code\u003e 隔离级别（否则，快照会被立即丢弃，因为 \u003ccode\u003eREAD COMMITTED\u003c/code\u003e 模式会为每条命令获取一个新快照）。如果导入事务使用 \u003ccode\u003eSERIALIZABLE\u003c/code\u003e 隔离级别，则导出快照的事务也必须使用该隔离级别。此外，非只读的可串行化事务不能从只读事务导入快照。\u003c/p\u003e\u003c/section\u003e\u003csection\u003e\u003ch2\u003e注解\u003c/h2\u003e\u003cp\u003e如果执行\u003ccode\u003eSET TRANSACTION\u003c/code\u003e之前没有 \u003ccode\u003eSTART TRANSACTION\u003c/code\u003e或者 \u003ccode\u003eBEGIN\u003c/code\u003e，它会发出一条警告，除此之外没有任何效果。\u003c/p\u003e\u003cp\u003e可以不使用\u003ccode\u003eSET TRANSACTION\u003c/code\u003e，而是在 \u003ccode\u003eBEGIN\u003c/code\u003e或\u003ccode\u003eSTART TRANSACTION\u003c/code\u003e中指定所需的 \u003cem\u003e\u003ccode\u003etransaction_modes\u003c/code\u003e\u003c/em\u003e。但是，对于\u003ccode\u003eSET TRANSACTION SNAPSHOT\u003c/code\u003e，这种方式不可用。\u003c/p\u003e\u003cp\u003e会话默认的事务模式也可以通过配置参数\u003ca href=\"/docs/18/runtime-config-client.html#GUC-DEFAULT-TRANSACTION-ISOLATION\" rel=\"nofollow\"\u003edefault_transaction_isolation\u003c/a\u003e、\u003ca href=\"/docs/18/runtime-config-client.html#GUC-DEFAULT-TRANSACTION-READ-ONLY\" rel=\"nofollow\"\u003edefault_transaction_read_only\u003c/a\u003e和\u003ca href=\"/docs/18/runtime-config-client.html#GUC-DEFAULT-TRANSACTION-DEFERRABLE\" rel=\"nofollow\"\u003edefault_transaction_deferrable\u003c/a\u003e来设置或检查（实际上，\u003ccode\u003eSET SESSION CHARACTERISTICS\u003c/code\u003e只是用 \u003ccode\u003eSET\u003c/code\u003e设置这些变量的一种更冗长的等价写法）。这意味着可以通过配置文件、\u003ccode\u003eALTER DATABASE\u003c/code\u003e等方式设置默认值。详见\u003ca href=\"/docs/18/runtime-config.html\" rel=\"nofollow\"\u003e第 19 章\u003c/a\u003e。\u003c/p\u003e\u003cp\u003e当前事务的模式也可以类似地通过配置参数\u003ca href=\"/docs/18/runtime-config-client.html#GUC-TRANSACTION-ISOLATION\" rel=\"nofollow\"\u003etransaction_isolation\u003c/a\u003e、\u003ca href=\"/docs/18/runtime-config-client.html#GUC-TRANSACTION-READ-ONLY\" rel=\"nofollow\"\u003etransaction_read_only\u003c/a\u003e和\u003ca href=\"/docs/18/runtime-config-client.html#GUC-TRANSACTION-DEFERRABLE\" rel=\"nofollow\"\u003etransaction_deferrable\u003c/a\u003e来设置或检查。设置其中任一参数的作用都与对应的\u003ccode\u003eSET TRANSACTION\u003c/code\u003e选项相同，并且在可设置时机方面有相同的限制。但是，这些参数不能在配置文件中设置，也不能通过实时执行的 SQL 之外的任何来源来设置。\u003c/p\u003e\u003c/section\u003e\u003csection\u003e\u003ch2\u003e示例\u003c/h2\u003e\u003cp\u003e要以与某个现有事务相同的快照开始一个新事务，先从该现有事务导出快照。这样会返回快照标识符，例如：\u003c/p\u003e\u003cpre\u003eBEGIN TRANSACTION ISOLATION LEVEL REPEATABLE READ;\nSELECT pg_export_snapshot();\n pg_export_snapshot\n---------------------\n 00000003-0000001B-1\n(1 row)\n\u003c/pre\u003e\u003cp\u003e然后在新开启事务的开始处，通过\u003ccode\u003eSET TRANSACTION SNAPSHOT\u003c/code\u003e命令给出该快照标识符：\u003c/p\u003e\u003cpre\u003eBEGIN TRANSACTION ISOLATION LEVEL REPEATABLE READ;\nSET TRANSACTION SNAPSHOT \u0026#39;00000003-0000001B-1\u0026#39;;\n\u003c/pre\u003e\u003c/section\u003e\u003csection\u003e\u003ch2\u003e兼容性\u003c/h2\u003e\u003cp\u003e这些命令由\u003cacronym\u003eSQL\u003c/acronym\u003e标准定义，但 \u003ccode\u003eDEFERRABLE\u003c/code\u003e事务模式和 \u003ccode\u003eSET TRANSACTION SNAPSHOT\u003c/code\u003e这种形式除外，它们是 \u003cspan\u003ePostgreSQL\u003c/span\u003e扩展。\u003c/p\u003e\u003cp\u003e\u003ccode\u003eSERIALIZABLE\u003c/code\u003e是标准中的默认事务隔离级别。在 \u003cspan\u003ePostgreSQL\u003c/span\u003e中，默认值通常是 \u003ccode\u003eREAD COMMITTED\u003c/code\u003e，但你可以按上述方式修改。\u003c/p\u003e\u003cp\u003e在 SQL 标准中，还可以用这些命令设置另一项事务特性：诊断区域的大小。这个概念特定于嵌入式 SQL，因此没有在 \u003cspan\u003ePostgreSQL\u003c/span\u003e服务器中实现。\u003c/p\u003e\u003cp\u003eSQL 标准要求在连续的\u003cem\u003e\u003ccode\u003etransaction_modes\u003c/code\u003e\u003c/em\u003e之间有逗号，但出于历史原因，\u003cspan\u003ePostgreSQL\u003c/span\u003e允许省略逗号。\u003c/p\u003e\u003c/section\u003e","SourceRevision":"1b5ca64c","ContentHash":"28a4053a527e2720c817a0e903e4c72857b86d9c29348586ea2f623a93aff9ae","Payload":{"purpose_zh":"设置当前事务的特性","sections":[{"html":"\u003cp\u003e\u003ccode class=\"command\"\u003eSET TRANSACTION\u003c/code\u003e命令设置当前事务的特性。它对任何后续事务都没有影响。\u003ccode class=\"command\"\u003eSET SESSION CHARACTERISTICS\u003c/code\u003e设置一个会话中后续事务的默认事务特性。对于单个事务，这些默认值可以用 \u003ccode class=\"command\"\u003eSET TRANSACTION\u003c/code\u003e覆盖。\u003c/p\u003e\u003cp\u003e可用的事务特性是事务隔离级别、事务访问模式（读/写或只读）以及可延迟模式。此外，还可以选择一个快照，不过它只能用于当前事务，不能作为会话默认值。\u003c/p\u003e\u003cp\u003e一个事务的隔离级别决定当其他事务并发运行时该事务能看见什么数据：\u003c/p\u003e\u003cdiv class=\"variablelist\"\u003e\u003cdl class=\"variablelist\"\u003e\u003cdt\u003e\u003cspan class=\"term\"\u003e\u003ccode class=\"literal\"\u003eREAD COMMITTED\u003c/code\u003e\u003c/span\u003e\u003c/dt\u003e\u003cdd\u003e\u003cp\u003e一条语句只能看到在它开始之前已提交的行。这是默认值。\u003c/p\u003e\u003c/dd\u003e\u003cdt\u003e\u003cspan class=\"term\"\u003e\u003ccode class=\"literal\"\u003eREPEATABLE READ\u003c/code\u003e\u003c/span\u003e\u003c/dt\u003e\u003cdd\u003e\u003cp\u003e当前事务中的所有语句都只能看到在该事务中执行第一条查询或数据修改语句之前已提交的行。\u003c/p\u003e\u003c/dd\u003e\u003cdt\u003e\u003cspan class=\"term\"\u003e\u003ccode class=\"literal\"\u003eSERIALIZABLE\u003c/code\u003e\u003c/span\u003e\u003c/dt\u003e\u003cdd\u003e\u003cp\u003e当前事务中的所有语句都只能看到在该事务中执行第一条查询或数据修改语句之前已提交的行。如果并发的可串行化事务之间出现某种读写模式，而这种情况不可能在这些事务的任何串行（一次执行一个）执行中发生，那么其中一个事务将以 \u003ccode class=\"literal\"\u003eserialization_failure\u003c/code\u003e错误回滚。\u003c/p\u003e\u003c/dd\u003e\u003c/dl\u003e\u003c/div\u003e\u003cp\u003eSQL 标准还定义了一个额外的级别：\u003ccode class=\"literal\"\u003eREAD UNCOMMITTED\u003c/code\u003e。在 \u003cspan class=\"productname\"\u003ePostgreSQL\u003c/span\u003e中，\u003ccode class=\"literal\"\u003eREAD UNCOMMITTED\u003c/code\u003e被视为 \u003ccode class=\"literal\"\u003eREAD COMMITTED\u003c/code\u003e。\u003c/p\u003e\u003cp\u003e在事务执行第一条查询或数据修改语句（\u003ccode class=\"command\"\u003eSELECT\u003c/code\u003e，\u003ccode class=\"command\"\u003eINSERT\u003c/code\u003e，\u003ccode class=\"command\"\u003eDELETE\u003c/code\u003e，\u003ccode class=\"command\"\u003eUPDATE\u003c/code\u003e，\u003ccode class=\"command\"\u003eMERGE\u003c/code\u003e，\u003ccode class=\"command\"\u003eFETCH\u003c/code\u003e，或 \u003ccode class=\"command\"\u003eCOPY\u003c/code\u003e）之后，事务隔离级别就不能再更改。有关事务隔离和并发控制的更多信息，请参见\u003ca href=\"/docs/18/mvcc.html\" title=\"第 13 章 并发控制\"\u003e第 13 章\u003c/a\u003e。\u003c/p\u003e\u003cp\u003e事务访问模式决定事务是读/写还是只读。读/写是默认值。当事务为只读时，下列 SQL 命令会被禁止：\u003ccode class=\"command\"\u003eINSERT\u003c/code\u003e、\u003ccode class=\"command\"\u003eUPDATE\u003c/code\u003e、\u003ccode class=\"command\"\u003eDELETE\u003c/code\u003e、\u003ccode class=\"command\"\u003eMERGE\u003c/code\u003e 以及 \u003ccode class=\"command\"\u003eCOPY FROM\u003c/code\u003e，前提是它们要写入的表不是临时表；所有 \u003ccode class=\"literal\"\u003eCREATE\u003c/code\u003e、\u003ccode class=\"literal\"\u003eALTER\u003c/code\u003e 和 \u003ccode class=\"literal\"\u003eDROP\u003c/code\u003e 命令；\u003ccode class=\"literal\"\u003eCOMMENT\u003c/code\u003e、\u003ccode class=\"literal\"\u003eGRANT\u003c/code\u003e、\u003ccode class=\"literal\"\u003eREVOKE\u003c/code\u003e、\u003ccode class=\"literal\"\u003eTRUNCATE\u003c/code\u003e；以及 \u003ccode class=\"literal\"\u003eEXPLAIN ANALYZE\u003c/code\u003e 和 \u003ccode class=\"literal\"\u003eEXECUTE\u003c/code\u003e，前提是它们要执行的命令属于上述列表。这是一个较高层面的只读概念，并不会阻止所有写入磁盘的行为。\u003c/p\u003e\u003cp\u003e只有当事务同时是\u003ccode class=\"literal\"\u003eSERIALIZABLE\u003c/code\u003e和 \u003ccode class=\"literal\"\u003eREAD ONLY\u003c/code\u003e时，\u003ccode class=\"literal\"\u003eDEFERRABLE\u003c/code\u003e 事务属性才会生效。当为一个事务同时选择这三个属性时，该事务在首次获取其快照时可能会阻塞；在此之后，它便可以运行，而无需承担普通 \u003ccode class=\"literal\"\u003eSERIALIZABLE\u003c/code\u003e事务的常规开销，也不会有促成串行化失败或因串行化失败而被取消的风险。这种模式非常适合长时间运行的报表或备份。\u003c/p\u003e\u003cp\u003e\u003ccode class=\"literal\"\u003eSET TRANSACTION SNAPSHOT\u003c/code\u003e命令允许一个新事务使用与现有事务相同的\u003cem class=\"firstterm\"\u003e快照\u003c/em\u003e运行。已有事务必须用 \u003ccode class=\"literal\"\u003epg_export_snapshot\u003c/code\u003e函数导出其快照（参见\u003ca href=\"/docs/18/functions-admin.html#FUNCTIONS-SNAPSHOT-SYNCHRONIZATION\" title=\"9.28.5. 快照同步函数\"\u003e第 9.28.5 节\u003c/a\u003e）。该函数会返回一个快照标识符，必须将其提供给\u003ccode class=\"literal\"\u003eSET TRANSACTION SNAPSHOT\u003c/code\u003e以指定要导入的快照。该标识符在此命令中必须写成字符串字面量，例如 \u003ccode class=\"literal\"\u003e'00000003-0000001B-1'\u003c/code\u003e。\u003ccode class=\"literal\"\u003eSET TRANSACTION SNAPSHOT\u003c/code\u003e只能在事务开始时执行，也就是在事务的第一条查询或数据修改语句（\u003ccode class=\"command\"\u003eSELECT\u003c/code\u003e、\u003ccode class=\"command\"\u003eINSERT\u003c/code\u003e、\u003ccode class=\"command\"\u003eDELETE\u003c/code\u003e、\u003ccode class=\"command\"\u003eUPDATE\u003c/code\u003e、\u003ccode class=\"command\"\u003eMERGE\u003c/code\u003e、\u003ccode class=\"command\"\u003eFETCH\u003c/code\u003e 或 \u003ccode class=\"command\"\u003eCOPY\u003c/code\u003e）之前。此外，事务还必须已经设置为 \u003ccode class=\"literal\"\u003eSERIALIZABLE\u003c/code\u003e 或 \u003ccode class=\"literal\"\u003eREPEATABLE READ\u003c/code\u003e 隔离级别（否则，快照会被立即丢弃，因为 \u003ccode class=\"literal\"\u003eREAD COMMITTED\u003c/code\u003e 模式会为每条命令获取一个新快照）。如果导入事务使用 \u003ccode class=\"literal\"\u003eSERIALIZABLE\u003c/code\u003e 隔离级别，则导出快照的事务也必须使用该隔离级别。此外，非只读的可串行化事务不能从只读事务导入快照。\u003c/p\u003e","key":"description","title":"描述"},{"html":"\u003cp\u003e如果执行\u003ccode class=\"command\"\u003eSET TRANSACTION\u003c/code\u003e之前没有 \u003ccode class=\"command\"\u003eSTART TRANSACTION\u003c/code\u003e或者 \u003ccode class=\"command\"\u003eBEGIN\u003c/code\u003e，它会发出一条警告，除此之外没有任何效果。\u003c/p\u003e\u003cp\u003e可以不使用\u003ccode class=\"command\"\u003eSET TRANSACTION\u003c/code\u003e，而是在 \u003ccode class=\"command\"\u003eBEGIN\u003c/code\u003e或\u003ccode class=\"command\"\u003eSTART TRANSACTION\u003c/code\u003e中指定所需的 \u003cem class=\"replaceable\"\u003e\u003ccode\u003etransaction_modes\u003c/code\u003e\u003c/em\u003e。但是，对于\u003ccode class=\"command\"\u003eSET TRANSACTION SNAPSHOT\u003c/code\u003e，这种方式不可用。\u003c/p\u003e\u003cp\u003e会话默认的事务模式也可以通过配置参数\u003ca href=\"/docs/18/runtime-config-client.html#GUC-DEFAULT-TRANSACTION-ISOLATION\"\u003edefault_transaction_isolation\u003c/a\u003e、\u003ca href=\"/docs/18/runtime-config-client.html#GUC-DEFAULT-TRANSACTION-READ-ONLY\"\u003edefault_transaction_read_only\u003c/a\u003e和\u003ca href=\"/docs/18/runtime-config-client.html#GUC-DEFAULT-TRANSACTION-DEFERRABLE\"\u003edefault_transaction_deferrable\u003c/a\u003e来设置或检查（实际上，\u003ccode class=\"command\"\u003eSET SESSION CHARACTERISTICS\u003c/code\u003e只是用 \u003ccode class=\"command\"\u003eSET\u003c/code\u003e设置这些变量的一种更冗长的等价写法）。这意味着可以通过配置文件、\u003ccode class=\"command\"\u003eALTER DATABASE\u003c/code\u003e等方式设置默认值。详见\u003ca href=\"/docs/18/runtime-config.html\" title=\"第 19 章 服务器配置\"\u003e第 19 章\u003c/a\u003e。\u003c/p\u003e\u003cp\u003e当前事务的模式也可以类似地通过配置参数\u003ca href=\"/docs/18/runtime-config-client.html#GUC-TRANSACTION-ISOLATION\"\u003etransaction_isolation\u003c/a\u003e、\u003ca href=\"/docs/18/runtime-config-client.html#GUC-TRANSACTION-READ-ONLY\"\u003etransaction_read_only\u003c/a\u003e和\u003ca href=\"/docs/18/runtime-config-client.html#GUC-TRANSACTION-DEFERRABLE\"\u003etransaction_deferrable\u003c/a\u003e来设置或检查。设置其中任一参数的作用都与对应的\u003ccode class=\"command\"\u003eSET TRANSACTION\u003c/code\u003e选项相同，并且在可设置时机方面有相同的限制。但是，这些参数不能在配置文件中设置，也不能通过实时执行的 SQL 之外的任何来源来设置。\u003c/p\u003e","key":"notes","title":"注解"},{"html":"\u003cp\u003e要以与某个现有事务相同的快照开始一个新事务，先从该现有事务导出快照。这样会返回快照标识符，例如：\u003c/p\u003e\u003cpre class=\"programlisting\"\u003eBEGIN TRANSACTION ISOLATION LEVEL REPEATABLE READ;\nSELECT pg_export_snapshot();\n pg_export_snapshot\n---------------------\n 00000003-0000001B-1\n(1 row)\n\u003c/pre\u003e\u003cp\u003e然后在新开启事务的开始处，通过\u003ccode class=\"command\"\u003eSET TRANSACTION SNAPSHOT\u003c/code\u003e命令给出该快照标识符：\u003c/p\u003e\u003cpre class=\"programlisting\"\u003eBEGIN TRANSACTION ISOLATION LEVEL REPEATABLE READ;\nSET TRANSACTION SNAPSHOT '00000003-0000001B-1';\n\u003c/pre\u003e","key":"examples","title":"示例"},{"html":"\u003cp\u003e这些命令由\u003cacronym\u003eSQL\u003c/acronym\u003e标准定义，但 \u003ccode class=\"literal\"\u003eDEFERRABLE\u003c/code\u003e事务模式和 \u003ccode class=\"command\"\u003eSET TRANSACTION SNAPSHOT\u003c/code\u003e这种形式除外，它们是 \u003cspan class=\"productname\"\u003ePostgreSQL\u003c/span\u003e扩展。\u003c/p\u003e\u003cp\u003e\u003ccode class=\"literal\"\u003eSERIALIZABLE\u003c/code\u003e是标准中的默认事务隔离级别。在 \u003cspan class=\"productname\"\u003ePostgreSQL\u003c/span\u003e中，默认值通常是 \u003ccode class=\"literal\"\u003eREAD COMMITTED\u003c/code\u003e，但你可以按上述方式修改。\u003c/p\u003e\u003cp\u003e在 SQL 标准中，还可以用这些命令设置另一项事务特性：诊断区域的大小。这个概念特定于嵌入式 SQL，因此没有在 \u003cspan class=\"productname\"\u003ePostgreSQL\u003c/span\u003e服务器中实现。\u003c/p\u003e\u003cp\u003eSQL 标准要求在连续的\u003cem class=\"replaceable\"\u003e\u003ccode\u003etransaction_modes\u003c/code\u003e\u003c/em\u003e之间有逗号，但出于历史原因，\u003cspan class=\"productname\"\u003ePostgreSQL\u003c/span\u003e允许省略逗号。\u003c/p\u003e","key":"compatibility","title":"兼容性"}],"sections_same_as":"","synopsis_html":"SET TRANSACTION \u003cem class=\"replaceable\"\u003e\u003ccode\u003etransaction_mode\u003c/code\u003e\u003c/em\u003e [, ...]\nSET TRANSACTION SNAPSHOT \u003cem class=\"replaceable\"\u003e\u003ccode\u003esnapshot_id\u003c/code\u003e\u003c/em\u003e\nSET SESSION CHARACTERISTICS AS TRANSACTION \u003cem class=\"replaceable\"\u003e\u003ccode\u003etransaction_mode\u003c/code\u003e\u003c/em\u003e [, ...]\n\n\u003cspan class=\"phrase\"\u003e其中 \u003cem class=\"replaceable\"\u003e\u003ccode\u003etransaction_mode\u003c/code\u003e\u003c/em\u003e 是下列之一：\u003c/span\u003e\n\n    ISOLATION LEVEL { SERIALIZABLE | REPEATABLE READ | READ COMMITTED | READ UNCOMMITTED }\n    READ WRITE | READ ONLY\n    [ NOT ] DEFERRABLE","synopsis_text":"SET TRANSACTION transaction_mode [, ...]\nSET TRANSACTION SNAPSHOT snapshot_id\nSET SESSION CHARACTERISTICS AS TRANSACTION transaction_mode [, ...]\n\n其中 transaction_mode 是下列之一：\n\nISOLATION LEVEL { SERIALIZABLE | REPEATABLE READ | READ COMMITTED | READ UNCOMMITTED }\nREAD WRITE | READ ONLY\n[ NOT ] DEFERRABLE"}},"RequestedLocale":"zh-Hans","Fallback":false,"Versions":["10","11","12","13","14","15","16","17","18","19","20","7.1","7.2","7.3","7.4","8.0","8.1","8.2","8.3","8.4","9.0","9.1","9.2","9.3","9.4","9.5","9.6"],"Locales":["en","zh-Hans"],"Signatures":null,"Spellings":null,"SQLState":null,"Evidence":null}
