~ubuntu-branches/ubuntu/utopic/pgadmin3/utopic

« back to all changes in this revision

Viewing changes to docs/en_US/pg/sql-prepare-transaction.html

  • Committer: Bazaar Package Importer
  • Author(s): Raphael Enrici, src/frm/frmBackup.cpp, debian/control
  • Date: 2006-10-06 21:06:48 UTC
  • mfrom: (1.2.1 upstream) (2.1.2 edgy)
  • Revision ID: james.westby@ubuntu.com-20061006210648-nscnazrse5jbwswf
* Patched frmBackup.cpp to ensure the schema is specified when backing up
  individual tables. (Closes: #387256)
  [src/frm/frmBackup.cpp]
* Cleaned up and updated description of the package. (Closes: #379188)
  [debian/control]

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
<html>
 
2
<head>
 
3
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
 
4
<title>PREPARE TRANSACTION</title>
 
5
<link rel="stylesheet" href="stylesheet.css" type="text/css">
 
6
<link rev="made" href="pgsql-docs@postgresql.org">
 
7
<meta name="generator" content="DocBook XSL Stylesheets V1.70.0">
 
8
<link rel="start" href="index.html" title="PostgreSQL 8.1.4 Documentation">
 
9
<link rel="up" href="sql-commands.html" title="SQL Commands">
 
10
<link rel="prev" href="sql-prepare.html" title="PREPARE">
 
11
<link rel="next" href="sql-reindex.html" title="REINDEX">
 
12
<link rel="copyright" href="ln-legalnotice.html" title="Legal Notice">
 
13
</head>
 
14
<body bgcolor="white" text="black" link="#0000FF" vlink="#840084" alink="#0000FF"><div class="refentry" lang="en">
 
15
<a name="sql-prepare-transaction"></a><div class="titlepage"></div>
 
16
<div class="refnamediv">
 
17
<h2>Name</h2>
 
18
<p>PREPARE TRANSACTION &#8212; prepare the current transaction for two-phase commit</p>
 
19
</div>
 
20
<a name="id779697"></a><div class="refsynopsisdiv">
 
21
<h2>Synopsis</h2>
 
22
<pre class="synopsis">PREPARE TRANSACTION <em class="replaceable"><code>transaction_id</code></em></pre>
 
23
</div>
 
24
<div class="refsect1" lang="en">
 
25
<a name="id779719"></a><h2>Description</h2>
 
26
<p>   <code class="command">PREPARE TRANSACTION</code> prepares the current transaction
 
27
   for two-phase commit. After this command, the transaction is no longer 
 
28
   associated with the current session; instead, its state is fully stored on
 
29
   disk, and there is a very high probability that it can be committed
 
30
   successfully, even if a database crash occurs before the commit is
 
31
   requested.
 
32
  </p>
 
33
<p>   Once prepared, a transaction can later be committed or rolled
 
34
   back with <code class="command">COMMIT PREPARED</code> or 
 
35
   <code class="command">ROLLBACK PREPARED</code>, respectively.  Those commands
 
36
   can be issued from any session, not only the one that executed the
 
37
   original transaction.
 
38
  </p>
 
39
<p>   From the point of view of the issuing session, <code class="command">PREPARE
 
40
   TRANSACTION</code> is not unlike a <code class="command">ROLLBACK</code> command:
 
41
   after executing it, there is no active current transaction, and the
 
42
   effects of the prepared transaction are no longer visible.  (The effects
 
43
   will become visible again if the transaction is committed.)
 
44
  </p>
 
45
<p>   If the <code class="command">PREPARE TRANSACTION</code> command fails for any
 
46
   reason, it becomes a <code class="command">ROLLBACK</code>: the current transaction
 
47
   is canceled.
 
48
  </p>
 
49
</div>
 
50
<div class="refsect1" lang="en">
 
51
<a name="id779796"></a><h2>Parameters</h2>
 
52
<div class="variablelist"><dl>
 
53
<dt><span class="term"><em class="replaceable"><code>transaction_id</code></em></span></dt>
 
54
<dd><p>      An arbitrary identifier that later identifies this transaction for
 
55
      <code class="command">COMMIT PREPARED</code> or <code class="command">ROLLBACK PREPARED</code>.
 
56
      The identifier must be written as a string literal, and must be
 
57
      less than 200 bytes long.  It must not be the same as the identifier
 
58
      used for any currently prepared transaction.
 
59
     </p></dd>
 
60
</dl></div>
 
61
</div>
 
62
<div class="refsect1" lang="en">
 
63
<a name="id779831"></a><h2>Notes</h2>
 
64
<p>   This command must be used inside a transaction block. Use
 
65
   <code class="command">BEGIN</code> to start one.
 
66
  </p>
 
67
<p>   It is not currently allowed to <code class="command">PREPARE</code> a transaction that
 
68
   has executed any operations involving temporary tables or
 
69
   created any cursors <code class="literal">WITH HOLD</code>.  Those features are too tightly
 
70
   tied to the current session to be useful in a transaction to be prepared.
 
71
  </p>
 
72
<p>   If the transaction modified any run-time parameters with <code class="command">SET</code>,
 
73
   those effects persist after <code class="command">PREPARE TRANSACTION</code>, and will not
 
74
   be affected by any later <code class="command">COMMIT PREPARED</code> or 
 
75
   <code class="command">ROLLBACK PREPARED</code>.  Thus, in this one respect
 
76
   <code class="command">PREPARE TRANSACTION</code> acts more like <code class="command">COMMIT</code> than
 
77
   <code class="command">ROLLBACK</code>.
 
78
  </p>
 
79
<p>   All currently available prepared transactions are listed in the
 
80
   <code class="structname">pg_prepared_xacts</code> system view.
 
81
  </p>
 
82
<p>   From a performance standpoint, it is unwise to leave transactions in
 
83
   the prepared state for a long time: this will for instance interfere with
 
84
   the ability of <code class="command">VACUUM</code> to reclaim storage.  Keep in mind also
 
85
   that the transaction continues to hold whatever locks it held.
 
86
   The intended
 
87
   usage of the feature is that a prepared transaction will normally be
 
88
   committed or rolled back as soon as an external transaction manager
 
89
   has verified that other databases are also prepared to commit.
 
90
  </p>
 
91
<p>   If you make any serious use of prepared transactions, you will probably
 
92
   want to increase the value of <a href="runtime-config-resource.html#guc-max-prepared-transactions">max_prepared_transactions</a>, as the default setting is
 
93
   quite small (to avoid wasting resources for those who don't use it).
 
94
   It is recommendable to make it at least equal to
 
95
   <a href="runtime-config-connection.html#guc-max-connections">max_connections</a>, so that every session can have
 
96
   a prepared transaction pending.
 
97
  </p>
 
98
</div>
 
99
<div class="refsect1" lang="en">
 
100
<a name="sql-prepare-transaction-examples"></a><h2>Examples</h2>
 
101
<p>   Prepare the current transaction for two-phase commit, using
 
102
   <code class="literal">foobar</code> as the transaction identifier:
 
103
   
 
104
</p>
 
105
<pre class="programlisting">PREPARE TRANSACTION 'foobar';</pre>
 
106
<p>
 
107
  </p>
 
108
</div>
 
109
<div class="refsect1" lang="en">
 
110
<a name="id779997"></a><h2>See Also</h2>
 
111
<span class="simplelist"><a href="sql-commit-prepared.html">COMMIT PREPARED</a>, <a href="sql-rollback-prepared.html">ROLLBACK PREPARED</a></span>
 
112
</div>
 
113
</div></body>
 
114
</html>