Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

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

Sign up
Appearance settings

Commitbc7d37a

Browse files
committed
Transaction IDs wrap around, per my proposal of 13-Aug-01. More
documentation to come, but the code is all here. initdb forced.
1 parentd1ee78f commitbc7d37a

File tree

29 files changed

+615
-169
lines changed

29 files changed

+615
-169
lines changed

‎doc/src/sgml/catalogs.sgml

Lines changed: 25 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<!--
22
Documentation of the system catalogs, directed toward PostgreSQL developers
3-
$Header: /cvsroot/pgsql/doc/src/sgml/catalogs.sgml,v 2.21 2001/08/21 16:35:58 tgl Exp $
3+
$Header: /cvsroot/pgsql/doc/src/sgml/catalogs.sgml,v 2.22 2001/08/26 16:55:58 tgl Exp $
44
-->
55

66
<chapter id="catalogs">
@@ -840,11 +840,34 @@
840840
<entry><type>oid</type></entry>
841841
<entry></entry>
842842
<entry>
843-
Lastoidinexistence afterthe database was created; useful
843+
Lastsystem OIDin the database; useful
844844
particularly to <application>pg_dump</application>
845845
</entry>
846846
</row>
847847

848+
<row>
849+
<entry>datvacuumxid</entry>
850+
<entry><type>xid</type></entry>
851+
<entry></entry>
852+
<entry>
853+
All tuples inserted or deleted by transaction IDs before this one
854+
have been marked as known committed or known aborted in this database.
855+
This is used to determine when commit-log space can be recycled.
856+
</entry>
857+
</row>
858+
859+
<row>
860+
<entry>datfrozenxid</entry>
861+
<entry><type>xid</type></entry>
862+
<entry></entry>
863+
<entry>
864+
All tuples inserted by transaction IDs before this one have been
865+
relabeled with a permanent (<quote>frozen</>) transaction ID in this
866+
database. This is useful to check whether a database must be vacuumed
867+
soon to avoid transaction ID wraparound problems.
868+
</entry>
869+
</row>
870+
848871
<row>
849872
<entry>datpath</entry>
850873
<entry><type>text</type></entry>

‎doc/src/sgml/ref/create_database.sgml

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<!--
2-
$Header: /cvsroot/pgsql/doc/src/sgml/ref/create_database.sgml,v 1.17 2000/11/15 19:43:39 petere Exp $
2+
$Header: /cvsroot/pgsql/doc/src/sgml/ref/create_database.sgml,v 1.18 2001/08/26 16:55:59 tgl Exp $
33
Postgres documentation
44
-->
55

@@ -284,6 +284,20 @@ comment from Olly; response from Thomas...
284284
simply by setting the flag false). The <literal>template0</literal>
285285
database is normally marked this way to prevent modification of it.
286286
</para>
287+
288+
<para>
289+
After preparing a template database, or making any changes to one,
290+
it is a good idea to perform
291+
<command>VACUUM FREEZE</> or <command>VACUUM FULL FREEZE</> in that
292+
database. If this is done when there are no other open transactions
293+
in the same database, then it is guaranteed that all tuples in the
294+
database are <quote>frozen</> and will not be subject to transaction
295+
ID wraparound problems. This is particularly important for a database
296+
that will have <literal>datallowconn</literal> set to false, since it
297+
will be impossible to do routine maintenance <command>VACUUM</>s on
298+
such a database.
299+
See the Administrator's Guide for more information.
300+
</para>
287301
</refsect2>
288302
</refsect1>
289303

‎doc/src/sgml/ref/vacuum.sgml

Lines changed: 37 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<!--
2-
$Header: /cvsroot/pgsql/doc/src/sgml/ref/vacuum.sgml,v 1.17 2001/07/10 22:09:28 tgl Exp $
2+
$Header: /cvsroot/pgsql/doc/src/sgml/ref/vacuum.sgml,v 1.18 2001/08/26 16:55:59 tgl Exp $
33
Postgres documentation
44
-->
55

@@ -20,11 +20,11 @@ Postgres documentation
2020
</refnamediv>
2121
<refsynopsisdiv>
2222
<refsynopsisdivinfo>
23-
<date>2001-07-10</date>
23+
<date>2001-08-26</date>
2424
</refsynopsisdivinfo>
2525
<synopsis>
26-
VACUUM [ FULL ] [ VERBOSE ] [ <replaceable class="PARAMETER">table</replaceable> ]
27-
VACUUM [ FULL ] [ VERBOSE ] ANALYZE [ <replaceable class="PARAMETER">table</replaceable> [ (<replaceable class="PARAMETER">column</replaceable> [, ...] ) ] ]
26+
VACUUM [ FULL ] [FREEZE ] [VERBOSE ] [ <replaceable class="PARAMETER">table</replaceable> ]
27+
VACUUM [ FULL ] [FREEZE ] [VERBOSE ] ANALYZE [ <replaceable class="PARAMETER">table</replaceable> [ (<replaceable class="PARAMETER">column</replaceable> [, ...] ) ] ]
2828
</synopsis>
2929

3030
<refsect2 id="R2-SQL-VACUUM-1">
@@ -46,6 +46,14 @@ VACUUM [ FULL ] [ VERBOSE ] ANALYZE [ <replaceable class="PARAMETER">table</repl
4646
</para>
4747
</listitem>
4848
</varlistentry>
49+
<varlistentry>
50+
<term>FREEZE</term>
51+
<listitem>
52+
<para>
53+
Selects aggressive <quote>freezing</quote> of tuples.
54+
</para>
55+
</listitem>
56+
</varlistentry>
4957
<varlistentry>
5058
<term>VERBOSE</term>
5159
<listitem>
@@ -169,21 +177,38 @@ NOTICE: Index <replaceable class="PARAMETER">index</replaceable>: Pages 28;
169177
</para>
170178

171179
<para>
172-
Plain <command>VACUUM</command> simply reclaims space and makes it
180+
<command>VACUUM ANALYZE</command> performs a <command>VACUUM</command>
181+
and then an <command>ANALYZE</command> for each selected table. This
182+
is a handy combination form for routine maintenance scripts. See
183+
<xref linkend="sql-analyze" endterm="sql-analyze-title">
184+
for more details about its processing.
185+
</para>
186+
187+
<para>
188+
Plain <command>VACUUM</command> (without <literal>FULL</>) simply reclaims
189+
space and makes it
173190
available for re-use. This form of the command can operate in parallel
174191
with normal reading and writing of the table. <command>VACUUM
175192
FULL</command> does more extensive processing, including moving of tuples
176193
across blocks to try to compact the table to the minimum number of disk
177-
blocks. This is much slower and requires an exclusive lock on each table
178-
while it is being processed.
194+
blocks. Thisformis much slower and requires an exclusive lock on each
195+
tablewhile it is being processed.
179196
</para>
180197

181198
<para>
182-
<command>VACUUM ANALYZE</command> performs a <command>VACUUM</command>
183-
and then an <command>ANALYZE</command> for each selected table. This
184-
is a handy combination form for routine maintenance scripts. See
185-
<xref linkend="sql-analyze" endterm="sql-analyze-title">
186-
for more details about its processing.
199+
<command>FREEZE</command> is a special-purpose option that
200+
causes tuples to be marked <quote>frozen</quote> as soon as possible,
201+
rather than waiting until they are quite old. If this is done when there
202+
are no other open transactions in the same database, then it is guaranteed
203+
that all tuples in the database are <quote>frozen</> and will not be
204+
subject to transaction ID wraparound problems, no matter how long the
205+
database is left un-vacuumed.
206+
<command>FREEZE</command> is not recommended for routine use. Its only
207+
intended usage is in connection with preparation of user-defined template
208+
databases, or other databases that are completely read-only and will not
209+
receive routine maintenance <command>VACUUM</> operations.
210+
See <xref linkend="sql-createdatabase" endterm="sql-createdatabase-title">
211+
for details.
187212
</para>
188213

189214
<refsect2 id="R2-SQL-VACUUM-3">

‎src/backend/access/transam/clog.c

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
* Portions Copyright (c) 1996-2001, PostgreSQL Global Development Group
1414
* Portions Copyright (c) 1994, Regents of the University of California
1515
*
16-
* $Header: /cvsroot/pgsql/src/backend/access/transam/clog.c,v 1.2 2001/08/25 23:24:39 tgl Exp $
16+
* $Header: /cvsroot/pgsql/src/backend/access/transam/clog.c,v 1.3 2001/08/26 16:55:59 tgl Exp $
1717
*
1818
*-------------------------------------------------------------------------
1919
*/
@@ -762,8 +762,12 @@ ExtendCLOG(TransactionId newestXact)
762762
{
763763
intpageno;
764764

765-
/* No work except at first XID of a page */
766-
if (TransactionIdToPgIndex(newestXact)!=0)
765+
/*
766+
* No work except at first XID of a page. But beware: just after
767+
* wraparound, the first XID of page zero is FirstNormalTransactionId.
768+
*/
769+
if (TransactionIdToPgIndex(newestXact)!=0&&
770+
!TransactionIdEquals(newestXact,FirstNormalTransactionId))
767771
return;
768772

769773
pageno=TransactionIdToPage(newestXact);
@@ -818,6 +822,18 @@ TruncateCLOG(TransactionId oldestXact)
818822
S_LOCK(&(ClogCtl->control_lck));
819823

820824
restart:;
825+
/*
826+
* While we are holding the lock, make an important safety check:
827+
* the planned cutoff point must be <= the current CLOG endpoint page.
828+
* Otherwise we have already wrapped around, and proceeding with the
829+
* truncation would risk removing the current CLOG segment.
830+
*/
831+
if (CLOGPagePrecedes(ClogCtl->latest_page_number,cutoffPage))
832+
{
833+
S_UNLOCK(&(ClogCtl->control_lck));
834+
elog(LOG,"unable to truncate commit log: apparent wraparound");
835+
return;
836+
}
821837

822838
for (slotno=0;slotno<NUM_CLOG_BUFFERS;slotno++)
823839
{

‎src/backend/access/transam/transam.c

Lines changed: 66 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
*
99
*
1010
* IDENTIFICATION
11-
* $Header: /cvsroot/pgsql/src/backend/access/transam/transam.c,v 1.47 2001/08/25 18:52:41 tgl Exp $
11+
* $Header: /cvsroot/pgsql/src/backend/access/transam/transam.c,v 1.48 2001/08/26 16:55:59 tgl Exp $
1212
*
1313
* NOTES
1414
* This file contains the high level access-method interface to the
@@ -236,3 +236,68 @@ TransactionIdAbort(TransactionId transactionId)
236236

237237
TransactionLogUpdate(transactionId,TRANSACTION_STATUS_ABORTED);
238238
}
239+
240+
241+
/*
242+
* TransactionIdPrecedes --- is id1 logically < id2?
243+
*/
244+
bool
245+
TransactionIdPrecedes(TransactionIdid1,TransactionIdid2)
246+
{
247+
/*
248+
* If either ID is a permanent XID then we can just do unsigned
249+
* comparison. If both are normal, do a modulo-2^31 comparison.
250+
*/
251+
int32diff;
252+
253+
if (!TransactionIdIsNormal(id1)|| !TransactionIdIsNormal(id2))
254+
return (id1<id2);
255+
256+
diff= (int32) (id1-id2);
257+
return (diff<0);
258+
}
259+
260+
/*
261+
* TransactionIdPrecedesOrEquals --- is id1 logically <= id2?
262+
*/
263+
bool
264+
TransactionIdPrecedesOrEquals(TransactionIdid1,TransactionIdid2)
265+
{
266+
int32diff;
267+
268+
if (!TransactionIdIsNormal(id1)|| !TransactionIdIsNormal(id2))
269+
return (id1 <=id2);
270+
271+
diff= (int32) (id1-id2);
272+
return (diff <=0);
273+
}
274+
275+
/*
276+
* TransactionIdFollows --- is id1 logically > id2?
277+
*/
278+
bool
279+
TransactionIdFollows(TransactionIdid1,TransactionIdid2)
280+
{
281+
int32diff;
282+
283+
if (!TransactionIdIsNormal(id1)|| !TransactionIdIsNormal(id2))
284+
return (id1>id2);
285+
286+
diff= (int32) (id1-id2);
287+
return (diff>0);
288+
}
289+
290+
/*
291+
* TransactionIdFollowsOrEquals --- is id1 logically >= id2?
292+
*/
293+
bool
294+
TransactionIdFollowsOrEquals(TransactionIdid1,TransactionIdid2)
295+
{
296+
int32diff;
297+
298+
if (!TransactionIdIsNormal(id1)|| !TransactionIdIsNormal(id2))
299+
return (id1 >=id2);
300+
301+
diff= (int32) (id1-id2);
302+
return (diff >=0);
303+
}

‎src/backend/access/transam/xid.c

Lines changed: 26 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -6,55 +6,44 @@
66
* Portions Copyright (c) 1996-2001, PostgreSQL Global Development Group
77
* Portions Copyright (c) 1994, Regents of the University of California
88
*
9-
*$Id: xid.c,v 1.32 2001/08/23 23:06:37 tgl Exp $
10-
*
11-
* OLD COMMENTS
12-
* XXX WARNING
13-
*Much of this file will change when we change our representation
14-
*of transaction ids -cim 3/23/90
15-
*
16-
* It is time to make the switch from 5 byte to 4 byte transaction ids
17-
* This file was totally reworked. -mer 5/22/92
9+
*$Id: xid.c,v 1.33 2001/08/26 16:55:59 tgl Exp $
1810
*
1911
*-------------------------------------------------------------------------
2012
*/
2113

2214
#include"postgres.h"
2315

16+
#include<limits.h>
17+
2418
#include"access/xact.h"
2519

20+
2621
#definePG_GETARG_TRANSACTIONID(n)DatumGetTransactionId(PG_GETARG_DATUM(n))
2722
#definePG_RETURN_TRANSACTIONID(x)return TransactionIdGetDatum(x)
2823

2924

3025
Datum
3126
xidin(PG_FUNCTION_ARGS)
3227
{
33-
char*representation=PG_GETARG_CSTRING(0);
28+
char*str=PG_GETARG_CSTRING(0);
3429

35-
PG_RETURN_TRANSACTIONID((TransactionId)atol(representation));
30+
PG_RETURN_TRANSACTIONID((TransactionId)strtoul(str,NULL,0));
3631
}
3732

3833
Datum
3934
xidout(PG_FUNCTION_ARGS)
4035
{
4136
TransactionIdtransactionId=PG_GETARG_TRANSACTIONID(0);
4237
/* maximum 32 bit unsigned integer representation takes 10 chars */
43-
char*representation=palloc(11);
38+
char*str=palloc(11);
4439

45-
snprintf(representation,11,"%lu", (unsigned long)transactionId);
40+
snprintf(str,11,"%lu", (unsigned long)transactionId);
4641

47-
PG_RETURN_CSTRING(representation);
42+
PG_RETURN_CSTRING(str);
4843
}
4944

50-
/* ----------------------------------------------------------------
51-
*xideq
52-
* ----------------------------------------------------------------
53-
*/
54-
5545
/*
56-
*xideq- returns 1, iff xid1 == xid2
57-
* 0 else;
46+
*xideq- are two xids equal?
5847
*/
5948
Datum
6049
xideq(PG_FUNCTION_ARGS)
@@ -64,3 +53,19 @@ xideq(PG_FUNCTION_ARGS)
6453

6554
PG_RETURN_BOOL(TransactionIdEquals(xid1,xid2));
6655
}
56+
57+
/*
58+
*xid_age- compute age of an XID (relative to current xact)
59+
*/
60+
Datum
61+
xid_age(PG_FUNCTION_ARGS)
62+
{
63+
TransactionIdxid=PG_GETARG_TRANSACTIONID(0);
64+
TransactionIdnow=GetCurrentTransactionId();
65+
66+
/* Permanent XIDs are always infinitely old */
67+
if (!TransactionIdIsNormal(xid))
68+
PG_RETURN_INT32(INT_MAX);
69+
70+
PG_RETURN_INT32((int32) (now-xid));
71+
}

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp