1PREPARE TRANSACTION(7)  PostgreSQL 9.2.24 Documentation PREPARE TRANSACTION(7)
2
3
4

NAME

6       PREPARE_TRANSACTION - prepare the current transaction for two-phase
7       commit
8

SYNOPSIS

10       PREPARE TRANSACTION transaction_id
11

DESCRIPTION

13       PREPARE TRANSACTION prepares the current transaction for two-phase
14       commit. After this command, the transaction is no longer associated
15       with the current session; instead, its state is fully stored on disk,
16       and there is a very high probability that it can be committed
17       successfully, even if a database crash occurs before the commit is
18       requested.
19
20       Once prepared, a transaction can later be committed or rolled back with
21       COMMIT PREPARED (COMMIT_PREPARED(7)) or ROLLBACK PREPARED
22       (ROLLBACK_PREPARED(7)), respectively. Those commands can be issued from
23       any session, not only the one that executed the original transaction.
24
25       From the point of view of the issuing session, PREPARE TRANSACTION is
26       not unlike a ROLLBACK command: after executing it, there is no active
27       current transaction, and the effects of the prepared transaction are no
28       longer visible. (The effects will become visible again if the
29       transaction is committed.)
30
31       If the PREPARE TRANSACTION command fails for any reason, it becomes a
32       ROLLBACK: the current transaction is canceled.
33

PARAMETERS

35       transaction_id
36           An arbitrary identifier that later identifies this transaction for
37           COMMIT PREPARED or ROLLBACK PREPARED. The identifier must be
38           written as a string literal, and must be less than 200 bytes long.
39           It must not be the same as the identifier used for any currently
40           prepared transaction.
41

NOTES

43       PREPARE TRANSACTION is not intended for use in applications or
44       interactive sessions. Its purpose is to allow an external transaction
45       manager to perform atomic global transactions across multiple databases
46       or other transactional resources. Unless you're writing a transaction
47       manager, you probably shouldn't be using PREPARE TRANSACTION.
48
49       This command must be used inside a transaction block. Use BEGIN(7) to
50       start one.
51
52       It is not currently allowed to PREPARE a transaction that has executed
53       any operations involving temporary tables, created any cursors WITH
54       HOLD, or executed LISTEN, UNLISTEN, or NOTIFY. Those features are too
55       tightly tied to the current session to be useful in a transaction to be
56       prepared.
57
58       If the transaction modified any run-time parameters with SET (without
59       the LOCAL option), those effects persist after PREPARE TRANSACTION, and
60       will not be affected by any later COMMIT PREPARED or ROLLBACK PREPARED.
61       Thus, in this one respect PREPARE TRANSACTION acts more like COMMIT
62       than ROLLBACK.
63
64       All currently available prepared transactions are listed in the
65       pg_prepared_xacts system view.
66
67           Caution
68           It is unwise to leave transactions in the prepared state for a long
69           time. This will interfere with the ability of VACUUM to reclaim
70           storage, and in extreme cases could cause the database to shut down
71           to prevent transaction ID wraparound (see Section 23.1.5,
72           “Preventing Transaction ID Wraparound Failures”, in the
73           documentation). Keep in mind also that the transaction continues to
74           hold whatever locks it held. The intended usage of the feature is
75           that a prepared transaction will normally be committed or rolled
76           back as soon as an external transaction manager has verified that
77           other databases are also prepared to commit.
78
79           If you have not set up an external transaction manager to track
80           prepared transactions and ensure they get closed out promptly, it
81           is best to keep the prepared-transaction feature disabled by
82           setting max_prepared_transactions to zero. This will prevent
83           accidental creation of prepared transactions that might then be
84           forgotten and eventually cause problems.
85

EXAMPLES

87       Prepare the current transaction for two-phase commit, using foobar as
88       the transaction identifier:
89
90           PREPARE TRANSACTION 'foobar';
91

COMPATIBILITY

93       PREPARE TRANSACTION is a PostgreSQL extension. It is intended for use
94       by external transaction management systems, some of which are covered
95       by standards (such as X/Open XA), but the SQL side of those systems is
96       not standardized.
97

SEE ALSO

99       COMMIT PREPARED (COMMIT_PREPARED(7)), ROLLBACK PREPARED
100       (ROLLBACK_PREPARED(7))
101
102
103
104PostgreSQL 9.2.24                 2017-11-06            PREPARE TRANSACTION(7)
Impressum