/ doc /
/doc/transactions.xml
1 <?xml version='1.0'?>
2 <!DOCTYPE appendix SYSTEM "/usr/share/xml/docbook/schema/dtd/5.0/docbook.dtd"
3 [
4 <!ENTITY plusmn "&#x00B1;"> <!-- recommended in case external
5 entity not available -->
6 <!-- Use symbols for repeating text. -->
7 <!ENTITY % entities SYSTEM "entities">
8 %entities;
9 ]>
10 <!-- Shouldn't have to use a system entity here.
11 <!DOCTYPE appendix PUBLIC "-//OASIS//DTD DocBook V5.0//EN"
12 "http://www.oasis-open.org/docbook/xml/5.0/docbook.dtd"
13 -->
14 <!-- Copyright 2012 (C) The Meme Factory, Inc. http://www.meme.com/
15 - Copyright © 1996-2011 by the PostgreSQL Global Development Group
16 -
17 - Distributed under the terms of the license of the University of
18 - California below.
19 -
20 - Permission to use, copy, modify, and distribute this software and
21 - its documentation for any purpose, without fee, and without a
22 - written agreement is hereby granted, provided that the above
23 - copyright notice and this paragraph and the following two paragraphs
24 - appear in all copies.
25 -
26 - IN NO EVENT SHALL THE UNIVERSITY OF CALIFORNIA BE LIABLE TO ANY
27 - PARTY FOR DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL
28 - DAMAGES, INCLUDING LOST PROFITS, ARISING OUT OF THE USE OF THIS
29 - SOFTWARE AND ITS DOCUMENTATION, EVEN IF THE UNIVERSITY OF CALIFORNIA
30 - HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31
32 - THE UNIVERSITY OF CALIFORNIA SPECIFICALLY DISCLAIMS ANY
33 - WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
34 - OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE
35 - SOFTWARE PROVIDED HEREUNDER IS ON AN "AS-IS" BASIS, AND THE
36 - UNIVERSITY OF CALIFORNIA HAS NO OBLIGATIONS TO PROVIDE MAINTENANCE,
37 - SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS.
38 -->
39
40 <appendix xml:id="transaction" xreflabel="transaction"
41 xmlns="http://docbook.org/ns/docbook"
42 version="5.0">
43 <title>&transaction_appendix;</title>
44
45 <note>
46 <para>This appendix is primarily excerpted from the &postgresql;
47 9.1 documentation chapter titled <quote><link
48 xlink:href="http://www.postgresql.org/docs/9.1/static/tutorial-transactions.html">Transactions</link></quote>.</para>
49 </note>
50
51 <para>Transactions are a fundamental concept of all database
52 systems. The essential point of a transaction is that it bundles
53 multiple steps into a single, all-or-nothing operation. The
54 intermediate states between the steps are not visible to other
55 concurrent transactions, and if some failure occurs that prevents
56 the transaction from completing, then none of the steps affect the
57 database at all.</para>
58
59 <para>Another important property of transactional databases is
60 closely related to the notion of atomic updates: when multiple
61 transactions are running concurrently, each one should not be able
62 to see the incomplete changes made by others.</para>
63
64 <para>In PostgreSQL, a transaction is set up by surrounding the
65 SQL commands of the transaction with <code>BEGIN</code> and
66 <code>COMMIT</code> commands. So a banking transaction would
67 actually look like:</para>
68
69 <literallayout><code>
70 BEGIN;
71 UPDATE accounts SET balance = balance - 100.00
72 WHERE name = 'Alice';
73 -- etc etc
74 COMMIT;
75 </code></literallayout>
76
77 <para>If, partway through the transaction, we decide we do not
78 want to commit (perhaps we just noticed that Alice's balance went
79 negative), we can issue the command <code>ROLLBACK</code> instead
80 of <code>COMMIT</code>, and all our updates so far will be
81 canceled.</para>
82
83 <para>PostgreSQL actually treats every SQL statement as being
84 executed within a transaction. If you do not issue a
85 <code>BEGIN</code> command, then each individual statement has an
86 implicit <code>BEGIN</code> and (if successful)
87 <code>COMMIT</code> wrapped around it.</para>
88
89 <para>The entirely of each file uploaded using &ppa; is committed
90 to the database in a transaction.</para>
91 </appendix>
92 <!--
93 Local Variables:
94 mode: nxml
95 End:
96 -->
97
98 <!-- LocalWords: xreflabel ulink url postgresql checkbox
99 -->