Skip to content

Navigation Menu

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 66bc9d2

Browse filesBrowse files
committed
doc: add transaction processing chapter with internals info
This also adds references to this new chapter at relevant sections of our documentation. Previously much of these internal details were exposed to users, but not explained. This also updates RELEASE SAVEPOINT. Discussion: https://postgr.es/m/CANbhV-E_iy9fmrErxrCh8TZTyenpfo72Hf_XD2HLDppva4dUNA@mail.gmail.com Author: Simon Riggs, Laurenz Albe Reviewed-by: Bruce Momjian Backpatch-through: 11
1 parent d18655c commit 66bc9d2
Copy full SHA for 66bc9d2

14 files changed

+292
-44
lines changed

‎doc/src/sgml/config.sgml

Copy file name to clipboardExpand all lines: doc/src/sgml/config.sgml
+4-2Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7211,12 +7211,14 @@ local0.* /var/log/postgresql
72117211
</row>
72127212
<row>
72137213
<entry><literal>%v</literal></entry>
7214-
<entry>Virtual transaction ID (backendID/localXID)</entry>
7214+
<entry>Virtual transaction ID (backendID/localXID); see
7215+
<xref linkend="transaction-id"/></entry>
72157216
<entry>no</entry>
72167217
</row>
72177218
<row>
72187219
<entry><literal>%x</literal></entry>
7219-
<entry>Transaction ID (0 if none is assigned)</entry>
7220+
<entry>Transaction ID (0 if none is assigned); see
7221+
<xref linkend="transaction-id"/></entry>
72207222
<entry>no</entry>
72217223
</row>
72227224
<row>

‎doc/src/sgml/datatype.sgml

Copy file name to clipboardExpand all lines: doc/src/sgml/datatype.sgml
+2-1Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4992,7 +4992,8 @@ WHERE ...
49924992
<structfield>xmin</structfield> and <structfield>xmax</structfield>. Transaction identifiers are 32-bit quantities.
49934993
In some contexts, a 64-bit variant <type>xid8</type> is used. Unlike
49944994
<type>xid</type> values, <type>xid8</type> values increase strictly
4995-
monotonically and cannot be reused in the lifetime of a database cluster.
4995+
monotonically and cannot be reused in the lifetime of a database
4996+
cluster. See <xref linkend="transaction-id"/> for more details.
49964997
</para>
49974998

49984999
<para>

‎doc/src/sgml/filelist.sgml

Copy file name to clipboardExpand all lines: doc/src/sgml/filelist.sgml
+1Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,7 @@
104104
<!ENTITY protocol SYSTEM "protocol.sgml">
105105
<!ENTITY sources SYSTEM "sources.sgml">
106106
<!ENTITY storage SYSTEM "storage.sgml">
107+
<!ENTITY transaction SYSTEM "xact.sgml">
107108
<!ENTITY tablesample-method SYSTEM "tablesample-method.sgml">
108109
<!ENTITY generic-wal SYSTEM "generic-wal.sgml">
109110
<!ENTITY custom-rmgr SYSTEM "custom-rmgr.sgml">

‎doc/src/sgml/func.sgml

Copy file name to clipboardExpand all lines: doc/src/sgml/func.sgml
+15-5Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -24677,7 +24677,10 @@ SELECT collation for ('foo' COLLATE "de_DE");
2467724677
<para>
2467824678
Returns the current transaction's ID. It will assign a new one if the
2467924679
current transaction does not have one already (because it has not
24680-
performed any database updates).
24680+
performed any database updates); see <xref
24681+
linkend="transaction-id"/> for details. If executed in a
24682+
subtransaction, this will return the top-level transaction ID;
24683+
see <xref linkend="subxacts"/> for details.
2468124684
</para></entry>
2468224685
</row>
2468324686

@@ -24694,6 +24697,8 @@ SELECT collation for ('foo' COLLATE "de_DE");
2469424697
ID is assigned yet. (It's best to use this variant if the transaction
2469524698
might otherwise be read-only, to avoid unnecessary consumption of an
2469624699
XID.)
24700+
If executed in a subtransaction, this will return the top-level
24701+
transaction ID.
2469724702
</para></entry>
2469824703
</row>
2469924704

@@ -24737,6 +24742,9 @@ SELECT collation for ('foo' COLLATE "de_DE");
2473724742
<para>
2473824743
Returns a current <firstterm>snapshot</firstterm>, a data structure
2473924744
showing which transaction IDs are now in-progress.
24745+
Only top-level transaction IDs are included in the snapshot;
24746+
subtransaction IDs are not shown; see <xref linkend="subxacts"/>
24747+
for details.
2474024748
</para></entry>
2474124749
</row>
2474224750

@@ -24791,7 +24799,8 @@ SELECT collation for ('foo' COLLATE "de_DE");
2479124799
Is the given transaction ID <firstterm>visible</firstterm> according
2479224800
to this snapshot (that is, was it completed before the snapshot was
2479324801
taken)? Note that this function will not give the correct answer for
24794-
a subtransaction ID.
24802+
a subtransaction ID (subxid); see <xref linkend="subxacts"/> for
24803+
details.
2479524804
</para></entry>
2479624805
</row>
2479724806
</tbody>
@@ -24803,8 +24812,9 @@ SELECT collation for ('foo' COLLATE "de_DE");
2480324812
wraps around every 4 billion transactions. However,
2480424813
the functions shown in <xref linkend="functions-pg-snapshot"/> use a
2480524814
64-bit type <type>xid8</type> that does not wrap around during the life
24806-
of an installation, and can be converted to <type>xid</type> by casting if
24807-
required. The data type <type>pg_snapshot</type> stores information about
24815+
of an installation and can be converted to <type>xid</type> by casting if
24816+
required; see <xref linkend="transaction-id"/> for details.
24817+
The data type <type>pg_snapshot</type> stores information about
2480824818
transaction ID visibility at a particular moment in time. Its components
2480924819
are described in <xref linkend="functions-pg-snapshot-parts"/>.
2481024820
<type>pg_snapshot</type>'s textual representation is
@@ -24850,7 +24860,7 @@ SELECT collation for ('foo' COLLATE "de_DE");
2485024860
xmax</literal> and not in this list was already completed at the time
2485124861
of the snapshot, and thus is either visible or dead according to its
2485224862
commit status. This list does not include the transaction IDs of
24853-
subtransactions.
24863+
subtransactions (subxids).
2485424864
</entry>
2485524865
</row>
2485624866
</tbody>

‎doc/src/sgml/glossary.sgml

Copy file name to clipboardExpand all lines: doc/src/sgml/glossary.sgml
+2-1Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1777,7 +1777,8 @@
17771777
<literal>3</literal> (values under that are reserved) and the
17781778
epoch value is incremented by one.
17791779
In some contexts, the epoch and xid values are
1780-
considered together as a single 64-bit value.
1780+
considered together as a single 64-bit value; see <xref
1781+
linkend="transaction-id"/> for more details.
17811782
</para>
17821783
<para>
17831784
For more information, see

‎doc/src/sgml/monitoring.sgml

Copy file name to clipboardExpand all lines: doc/src/sgml/monitoring.sgml
+4-2Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -918,7 +918,8 @@ postgres 27093 0.0 0.0 30096 2752 ? Ss 11:34 0:00 postgres: ser
918918
<structfield>backend_xid</structfield> <type>xid</type>
919919
</para>
920920
<para>
921-
Top-level transaction identifier of this backend, if any.
921+
Top-level transaction identifier of this backend, if any; see
922+
<xref linkend="transaction-id"/>.
922923
</para></entry>
923924
</row>
924925

@@ -1890,7 +1891,8 @@ postgres 27093 0.0 0.0 30096 2752 ? Ss 11:34 0:00 postgres: ser
18901891
</row>
18911892
<row>
18921893
<entry><literal>virtualxid</literal></entry>
1893-
<entry>Waiting to acquire a virtual transaction ID lock.</entry>
1894+
<entry>Waiting to acquire a virtual transaction ID lock; see
1895+
<xref linkend="transaction-id"/>.</entry>
18941896
</row>
18951897
</tbody>
18961898
</tgroup>

‎doc/src/sgml/pgrowlocks.sgml

Copy file name to clipboardExpand all lines: doc/src/sgml/pgrowlocks.sgml
+2-1Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,8 @@ pgrowlocks(text) returns setof record
5757
<row>
5858
<entry><structfield>locker</structfield></entry>
5959
<entry><type>xid</type></entry>
60-
<entry>Transaction ID of locker, or multixact ID if multitransaction</entry>
60+
<entry>Transaction ID of locker, or multixact ID if
61+
multitransaction; see <xref linkend="transaction-id"/></entry>
6162
</row>
6263
<row>
6364
<entry><structfield>multi</structfield></entry>

‎doc/src/sgml/postgres.sgml

Copy file name to clipboardExpand all lines: doc/src/sgml/postgres.sgml
+1Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -271,6 +271,7 @@ break is not needed in a wider output rendering.
271271
&brin;
272272
&hash;
273273
&storage;
274+
&transaction;
274275
&bki;
275276
&planstats;
276277
&backup-manifest;

‎doc/src/sgml/ref/release_savepoint.sgml

Copy file name to clipboardExpand all lines: doc/src/sgml/ref/release_savepoint.sgml
+41-21Lines changed: 41 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ PostgreSQL documentation
2121

2222
<refnamediv>
2323
<refname>RELEASE SAVEPOINT</refname>
24-
<refpurpose>destroy a previously defined savepoint</refpurpose>
24+
<refpurpose>release a previously defined savepoint</refpurpose>
2525
</refnamediv>
2626

2727
<refsynopsisdiv>
@@ -34,23 +34,13 @@ RELEASE [ SAVEPOINT ] <replaceable>savepoint_name</replaceable>
3434
<title>Description</title>
3535

3636
<para>
37-
<command>RELEASE SAVEPOINT</command> destroys a savepoint previously defined
38-
in the current transaction.
39-
</para>
40-
41-
<para>
42-
Destroying a savepoint makes it unavailable as a rollback point,
43-
but it has no other user visible behavior. It does not undo the
44-
effects of commands executed after the savepoint was established.
45-
(To do that, see <xref linkend="sql-rollback-to"/>.)
46-
Destroying a savepoint when
47-
it is no longer needed allows the system to reclaim some resources
48-
earlier than transaction end.
49-
</para>
50-
51-
<para>
52-
<command>RELEASE SAVEPOINT</command> also destroys all savepoints that were
53-
established after the named savepoint was established.
37+
<command>RELEASE SAVEPOINT</command> releases the named savepoint and
38+
all active savepoints that were created after the named savepoint,
39+
and frees their resources. All changes made since the creation of
40+
the savepoint that didn't already get rolled back are merged into
41+
the transaction or savepoint that was active when the named savepoint
42+
was created. Changes made after <command>RELEASE SAVEPOINT</command>
43+
will also be part of this active transaction or savepoint.
5444
</para>
5545
</refsect1>
5646

@@ -62,7 +52,7 @@ RELEASE [ SAVEPOINT ] <replaceable>savepoint_name</replaceable>
6252
<term><replaceable>savepoint_name</replaceable></term>
6353
<listitem>
6454
<para>
65-
The name of the savepoint to destroy.
55+
The name of the savepoint to release.
6656
</para>
6757
</listitem>
6858
</varlistentry>
@@ -78,7 +68,7 @@ RELEASE [ SAVEPOINT ] <replaceable>savepoint_name</replaceable>
7868

7969
<para>
8070
It is not possible to release a savepoint when the transaction is in
81-
an aborted state.
71+
an aborted state; to do that, use <xref linkend="sql-rollback-to"/>.
8272
</para>
8373

8474
<para>
@@ -93,7 +83,7 @@ RELEASE [ SAVEPOINT ] <replaceable>savepoint_name</replaceable>
9383
<title>Examples</title>
9484

9585
<para>
96-
To establish and later destroy a savepoint:
86+
To establish and later release a savepoint:
9787
<programlisting>
9888
BEGIN;
9989
INSERT INTO table1 VALUES (3);
@@ -104,6 +94,36 @@ COMMIT;
10494
</programlisting>
10595
The above transaction will insert both 3 and 4.
10696
</para>
97+
98+
<para>
99+
A more complex example with multiple nested subtransactions:
100+
<programlisting>
101+
BEGIN;
102+
INSERT INTO table1 VALUES (1);
103+
SAVEPOINT sp1;
104+
INSERT INTO table1 VALUES (2);
105+
SAVEPOINT sp2;
106+
INSERT INTO table1 VALUES (3);
107+
RELEASE SAVEPOINT sp2;
108+
INSERT INTO table1 VALUES (4))); -- generates an error
109+
</programlisting>
110+
In this example, the application requests the release of the savepoint
111+
<literal>sp2</literal>, which inserted 3. This changes the insert's
112+
transaction context to <literal>sp1</literal>. When the statement
113+
attempting to insert value 4 generates an error, the insertion of 2 and
114+
4 are lost because they are in the same, now-rolled back savepoint,
115+
and value 3 is in the same transaction context. The application can
116+
now only choose one of these two commands, since all other commands
117+
will be ignored:
118+
<programlisting>
119+
ROLLBACK;
120+
ROLLBACK TO SAVEPOINT sp1;
121+
</programlisting>
122+
Choosing <command>ROLLBACK</command> will abort everything, including
123+
value 1, whereas <command>ROLLBACK TO SAVEPOINT sp1</command> will retain
124+
value 1 and allow the transaction to continue.
125+
</para>
126+
107127
</refsect1>
108128

109129
<refsect1>

‎doc/src/sgml/ref/rollback.sgml

Copy file name to clipboardExpand all lines: doc/src/sgml/ref/rollback.sgml
+4-4Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -56,10 +56,10 @@ ROLLBACK [ WORK | TRANSACTION ] [ AND [ NO ] CHAIN ]
5656
<term><literal>AND CHAIN</literal></term>
5757
<listitem>
5858
<para>
59-
If <literal>AND CHAIN</literal> is specified, a new transaction is
60-
immediately started with the same transaction characteristics (see <xref
61-
linkend="sql-set-transaction"/>) as the just finished one. Otherwise,
62-
no new transaction is started.
59+
If <literal>AND CHAIN</literal> is specified, a new (not aborted)
60+
transaction is immediately started with the same transaction
61+
characteristics (see <xref linkend="sql-set-transaction"/>) as the
62+
just finished one. Otherwise, no new transaction is started.
6363
</para>
6464
</listitem>
6565
</varlistentry>

‎doc/src/sgml/ref/rollback_to.sgml

Copy file name to clipboardExpand all lines: doc/src/sgml/ref/rollback_to.sgml
+3-2Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,9 @@ ROLLBACK [ WORK | TRANSACTION ] TO [ SAVEPOINT ] <replaceable>savepoint_name</re
3535

3636
<para>
3737
Roll back all commands that were executed after the savepoint was
38-
established. The savepoint remains valid and can be rolled back to
39-
again later, if needed.
38+
established and then start a new subtransaction at the same transaction level.
39+
The savepoint remains valid and can be rolled back to again later,
40+
if needed.
4041
</para>
4142

4243
<para>

‎doc/src/sgml/system-views.sgml

Copy file name to clipboardExpand all lines: doc/src/sgml/system-views.sgml
+4-3Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1434,7 +1434,8 @@
14341434
</para>
14351435
<para>
14361436
Virtual ID of the transaction targeted by the lock,
1437-
or null if the target is not a virtual transaction ID
1437+
or null if the target is not a virtual transaction ID; see
1438+
<xref linkend="transactions"/>
14381439
</para></entry>
14391440
</row>
14401441

@@ -1443,8 +1444,8 @@
14431444
<structfield>transactionid</structfield> <type>xid</type>
14441445
</para>
14451446
<para>
1446-
ID of the transaction targeted by the lock,
1447-
or null if the target is not a transaction ID
1447+
ID of the transaction targeted by the lock, or null if the target
1448+
is not a transaction ID; <xref linkend="transactions"/>
14481449
</para></entry>
14491450
</row>
14501451

‎doc/src/sgml/wal.sgml

Copy file name to clipboardExpand all lines: doc/src/sgml/wal.sgml
+4-2Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,9 @@
44
<title>Reliability and the Write-Ahead Log</title>
55

66
<para>
7-
This chapter explains how the Write-Ahead Log is used to obtain
8-
efficient, reliable operation.
7+
This chapter explains how to control the reliability of
8+
<productname>PostgreSQL</productname>, including details about the
9+
Write-Ahead Log.
910
</para>
1011

1112
<sect1 id="wal-reliability">
@@ -909,4 +910,5 @@
909910
seem to be a problem in practice.
910911
</para>
911912
</sect1>
913+
912914
</chapter>

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.