Home Explore Blog CI



postgresql

2nd chunk of `doc/src/sgml/ref/prepare_transaction.sgml`
9fdaa17859ac7bd12f90e1b2a45970d314c381a1bc26b7af0000000100000866
 arbitrary identifier that later identifies this transaction for
      <command>COMMIT PREPARED</command> or <command>ROLLBACK PREPARED</command>.
      The identifier must be written as a string literal, and must be
      less than 200 bytes long.  It must not be the same as the identifier
      used for any currently prepared transaction.
     </para>
    </listitem>
   </varlistentry>
  </variablelist>
 </refsect1>

 <refsect1>
  <title>Notes</title>

  <para>
   <command>PREPARE TRANSACTION</command> is not intended for use in applications
   or interactive sessions. Its purpose is to allow an external
   transaction manager to perform atomic global transactions across multiple
   databases or other transactional resources. Unless you're writing a
   transaction manager, you probably shouldn't be using <command>PREPARE
   TRANSACTION</command>.
  </para>

  <para>
   This command must be used inside a transaction block. Use <link
   linkend="sql-begin"><command>BEGIN</command></link> to start one.
  </para>

  <para>
   It is not currently allowed to <command>PREPARE</command> a transaction that
   has executed any operations involving temporary tables or the session's
   temporary namespace, created any cursors <literal>WITH HOLD</literal>, or
   executed <command>LISTEN</command>, <command>UNLISTEN</command>, or
   <command>NOTIFY</command>.
   Those features are too tightly
   tied to the current session to be useful in a transaction to be prepared.
  </para>

  <para>
   If the transaction modified any run-time parameters with <command>SET</command>
   (without the <literal>LOCAL</literal> option),
   those effects persist after <command>PREPARE TRANSACTION</command>, and will not
   be affected by any later <command>COMMIT PREPARED</command> or
   <command>ROLLBACK PREPARED</command>.  Thus, in this one respect
   <command>PREPARE TRANSACTION</command> acts more like <command>COMMIT</command> than
   <command>ROLLBACK</command>.
  </para>

  <para>
   All currently available prepared transactions are listed in the
   <link linkend="view-pg-prepared-xacts"><structname>pg_prepared_xacts</structname></link>

Title: PREPARE TRANSACTION: Parameters and Notes
Summary
The `transaction_id` parameter for `PREPARE TRANSACTION` is an identifier used in subsequent `COMMIT PREPARED` or `ROLLBACK PREPARED` commands. It must be a unique string literal (under 200 bytes). The command is designed for external transaction managers for atomic global transactions, not for typical applications. It must be used within a transaction block started with `BEGIN`. Transactions using temporary tables/namespaces, `WITH HOLD` cursors, or `LISTEN`/`UNLISTEN`/`NOTIFY` cannot be prepared. `SET` parameter changes persist after `PREPARE TRANSACTION`. All prepared transactions are listed in the `pg_prepared_xacts` view.