doc-exports/docs/dws/dev/dws_06_0262.html
Lu, Huayi e6fa411af0 DWS DEV 830.201 version
Reviewed-by: Pruthi, Vineet <vineet.pruthi@t-systems.com>
Co-authored-by: Lu, Huayi <luhuayi@huawei.com>
Co-committed-by: Lu, Huayi <luhuayi@huawei.com>
2024-05-16 07:24:04 +00:00

27 lines
4.6 KiB
HTML

<a name="EN-US_TOPIC_0000001233510129"></a><a name="EN-US_TOPIC_0000001233510129"></a>
<h1 class="topictitle1">PREPARE TRANSACTION</h1>
<div id="body8662426"><div class="section" id="EN-US_TOPIC_0000001233510129__sd491729b1c9d4bef96c287690100e19c"><h4 class="sectiontitle">Function</h4><p id="EN-US_TOPIC_0000001233510129__en-us_topic_0059779173_p11485361015">Prepares the current transaction for two-phase commit.</p>
<p id="EN-US_TOPIC_0000001233510129__a55d3892591724e10b57a8e5a90168f5a">After this command is executed, the transaction is no longer associated with the current session. Instead, its state is completely stored on disk, and it is highly likely to be committed successfully, even if the database crashes before.</p>
<p id="EN-US_TOPIC_0000001233510129__a8a572a45b1ef481794ff2afefafd8b5f">Once prepared, a transaction can later be committed or rolled back with <a href="dws_06_0260.html">COMMIT PREPARED</a> or <a href="dws_06_0268.html">ROLLBACK PREPARED</a>, respectively. Those commands can be issued from any session, not only the one that executed the original transaction. </p>
<p id="EN-US_TOPIC_0000001233510129__a589dbc0d8bc94cb285b937e389dccbdf">From the point of view of the issuing session, <strong id="EN-US_TOPIC_0000001233510129__b842352706155549">PREPARE TRANSACTION</strong> is not unlike a <strong id="EN-US_TOPIC_0000001233510129__b842352706155554">ROLLBACK</strong> command: after executing it, there is no active current transaction, and the effects of the prepared transaction are no longer visible. (The effects will become visible again if the transaction is committed.)</p>
<p id="EN-US_TOPIC_0000001233510129__a06154661f2594b3ca74b05a903d6df16">If the <strong id="EN-US_TOPIC_0000001233510129__b84235270615561">PREPARE TRANSACTION</strong> command fails for any reason, it becomes a <strong id="EN-US_TOPIC_0000001233510129__b84235270615567">ROLLBACK</strong> and the current transaction is canceled.</p>
</div>
<div class="section" id="EN-US_TOPIC_0000001233510129__s96c8274c5b1843499568b9ac926e901b"><h4 class="sectiontitle">Precautions</h4><ul id="EN-US_TOPIC_0000001233510129__u7acf62f0391b435cba155ffa2543dcf5"><li id="EN-US_TOPIC_0000001233510129__l551d433424274d1f97293066df377a6b">The transaction function is maintained automatically by the database, and should be not visible to users.</li><li id="EN-US_TOPIC_0000001233510129__l440d454b88574255b9fd7920d706f58a">When running the <strong id="EN-US_TOPIC_0000001233510129__b1812291379151112">PREPARE TRANSACTION</strong> command, increasing the value of <strong id="EN-US_TOPIC_0000001233510129__b210698822151112">max_prepared_transactions</strong> in configuration file <strong id="EN-US_TOPIC_0000001233510129__b858343011151112">postgresql.conf</strong>. You are advised to set <strong id="EN-US_TOPIC_0000001233510129__b572420575151128">max_prepared_transactions</strong> to a value not less than that of <strong id="EN-US_TOPIC_0000001233510129__b1113335325151128">max_connections</strong> so that one pending prepared transaction is available for each session.</li></ul>
</div>
<div class="section" id="EN-US_TOPIC_0000001233510129__sf3bb4a591e3b40ec8afdb0b1fab4c4e9"><h4 class="sectiontitle">Syntax</h4><pre class="screen" id="EN-US_TOPIC_0000001233510129__s3bc78252a733401681cd2edb58ed8f15">PREPARE TRANSACTION transaction_id;</pre>
</div>
<div class="section" id="EN-US_TOPIC_0000001233510129__s5c47ddc0f6dc4a32a5d23f50edf90b30"><h4 class="sectiontitle">Parameter Description</h4><p id="EN-US_TOPIC_0000001233510129__a09c6e19bb96148ab9e8bb2e622a21fb6"><strong id="EN-US_TOPIC_0000001233510129__a12d21b56ca754405aa47d89bf7a2ccf0">transaction_id</strong></p>
<p id="EN-US_TOPIC_0000001233510129__af55f3b1890824e45b7aa3cc8eca5bbc6">An arbitrary identifier that later identifies this transaction for <strong id="EN-US_TOPIC_0000001233510129__b84235270692036">COMMIT PREPARED</strong> or <strong id="EN-US_TOPIC_0000001233510129__b84235270692039">ROLLBACK PREPARED</strong>. The identifier must be different from those for current prepared transactions.</p>
<p id="EN-US_TOPIC_0000001233510129__a11299a78e898473b94bfc03ca5cf1bf0">Value range: The identifier must be written as a string literal, and must be less than 200 bytes long.</p>
</div>
<div class="section" id="EN-US_TOPIC_0000001233510129__s05b5e4a25dab41e4985cb55c2161f903"><h4 class="sectiontitle">Helpful Links</h4><p id="EN-US_TOPIC_0000001233510129__a1233d131018b42b0afe54a4f425f74fb"><a href="dws_06_0260.html">COMMIT PREPARED</a>, <a href="dws_06_0268.html">ROLLBACK PREPARED</a></p>
</div>
</div>
<div>
<div class="familylinks">
<div class="parentlink"><strong>Parent topic:</strong> <a href="dws_06_0254.html">TCL Syntax</a></div>
</div>
</div>