バージョンごとのドキュメント一覧

74.1. トランザクションと識別子 #

<title>Transactions and Identifiers</title>

Transactions can be created explicitly using <command>BEGIN</command> or <command>START TRANSACTION</command> and ended using <command>COMMIT</command> or <command>ROLLBACK</command>. SQL statements outside of explicit transactions automatically use single-statement transactions. トランザクションは、BEGINまたはSTART TRANSACTIONを使用して明示的に作成し、COMMITまたはROLLBACKを使用して終了します。 明示的なトランザクションの外側のSQL文は、自動的に単一文トランザクションを使用します。

Every transaction is identified by a unique <literal>VirtualTransactionId</literal> (also called <literal>virtualXID</literal> or <literal>vxid</literal>), which is comprised of a backend ID (or <literal>backendID</literal>) and a sequentially-assigned number local to each backend, known as <literal>localXID</literal>. For example, the virtual transaction ID <literal>4/12532</literal> has a <literal>backendID</literal> of <literal>4</literal> and a <literal>localXID</literal> of <literal>12532</literal>. 各トランザクションは、一意のVirtualTransactionId(あるいはvirtualXIDまたはvxidとも呼ばれます)で識別します。 これは、バックエンドID(またはbackendID)と、localXIDと呼ばれる各バックエンドに固有の連続した番号で構成されます。 たとえば、仮想トランザクションID4/12532backendID4で、localXID12532です。

Non-virtual <literal>TransactionId</literal>s (or <type>xid</type>), e.g., <literal>278394</literal>, are assigned sequentially to transactions from a global counter used by all databases within the <productname>PostgreSQL</productname> cluster. This assignment happens when a transaction first writes to the database. This means lower-numbered xids started writing before higher-numbered xids. Note that the order in which transactions perform their first database write might be different from the order in which the transactions started, particularly if the transaction started with statements that only performed database reads. 非仮想TransactionId(またはxid)、例えば278394は、PostgreSQLクラスタ内のすべてのデータベースが使用するグローバルカウンタからトランザクションに順番に割り当てられます。 この割り当ては、トランザクションがデータベースに最初に書き込みを行ったときに行われます。 これは、低い番号のxidが、より大きな番号のxidよりも前に書き込みを開始したことを意味します。 トランザクションが最初にデータベースに書き込みを行った順序は、トランザクションの開始順序とは異なるかもしれないことに注意してください。 特に、トランザクションがデータベース読み取りのみを実行する文で開始した場合にはそうなります。

The internal transaction ID type <type>xid</type> is 32 bits wide and <link linkend="vacuum-for-wraparound">wraps around</link> every 4 billion transactions. A 32-bit epoch is incremented during each wraparound. There is also a 64-bit type <type>xid8</type> which includes this epoch and therefore does not wrap around during the life of an installation; it can be converted to xid by casting. The functions in <xref linkend="functions-pg-snapshot"/> return <type>xid8</type> values. Xids are used as the basis for <productname>PostgreSQL</productname>'s <link linkend="mvcc">MVCC</link> concurrency mechanism and streaming replication. 内部トランザクションID型xidは32ビット幅で、40億トランザクションごとに周回します。 32ビットエポックは各周回ごとに加算されます。 また、このエポックを含むために、インストールの寿命中には周回しない64ビット型xid8もあり、キャストでxidに変換できます。 表 9.80の関数はxid8値を返します。 XIDはPostgreSQLMVCC同時実行機構とストリーミングレプリケーションの基礎として使用されます。

When a top-level transaction with a (non-virtual) xid commits, it is marked as committed in the <filename>pg_xact</filename> directory. Additional information is recorded in the <filename>pg_commit_ts</filename> directory if <xref linkend="guc-track-commit-timestamp"/> is enabled. (非仮想)xidを持つトップレベルのトランザクションがコミットすると、pg_xactディレクトリにコミット済みとしてマークされます。 track_commit_timestampが有効な場合、追加情報がpg_commit_tsディレクトリに記録されます。

In addition to <literal>vxid</literal> and <type>xid</type>, prepared transactions are also assigned Global Transaction Identifiers (<acronym>GID</acronym>). GIDs are string literals up to 200 bytes long, which must be unique amongst other currently prepared transactions. The mapping of GID to xid is shown in <link linkend="view-pg-prepared-xacts"><structname>pg_prepared_xacts</structname></link>. vxidxidに加えて、準備されたトランザクションにはグローバルトランザクション識別子(GID)も割り当てられます。 GIDは最大200バイト長の文字列リテラルで、現在準備されている他のトランザクション中で一意でなければなりません。 GIDからxidへのマッピングはpg_prepared_xactsに表示されます。