Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit f5b2f60

Browse files
committed
Change WAL-logging scheme for multixacts to be more like regular
transaction IDs, rather than like subtrans; in particular, the information now survives a database restart. Per previous discussion, this is essential for PITR log shipping and for 2PC.
1 parent 593badd commit f5b2f60

File tree

12 files changed

+555
-269
lines changed

12 files changed

+555
-269
lines changed

doc/src/sgml/ref/pg_resetxlog.sgml

Lines changed: 21 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<!--
2-
$PostgreSQL: pgsql/doc/src/sgml/ref/pg_resetxlog.sgml,v 1.10 2005/04/28 21:47:10 tgl Exp $
2+
$PostgreSQL: pgsql/doc/src/sgml/ref/pg_resetxlog.sgml,v 1.11 2005/06/08 15:50:21 tgl Exp $
33
PostgreSQL documentation
44
-->
55

@@ -23,6 +23,7 @@ PostgreSQL documentation
2323
<arg> -o <replaceable class="parameter">oid</replaceable> </arg>
2424
<arg> -x <replaceable class="parameter">xid</replaceable> </arg>
2525
<arg> -m <replaceable class="parameter">mxid</replaceable> </arg>
26+
<arg> -O <replaceable class="parameter">mxoff</replaceable> </arg>
2627
<arg> -l <replaceable class="parameter">timelineid</replaceable>,<replaceable class="parameter">fileid</replaceable>,<replaceable class="parameter">seg</replaceable> </arg>
2728
<arg choice="plain"><replaceable>datadir</replaceable></arg>
2829
</cmdsynopsis>
@@ -32,8 +33,8 @@ PostgreSQL documentation
3233
<title>Description</title>
3334
<para>
3435
<command>pg_resetxlog</command> clears the write-ahead log (WAL) and
35-
optionally resets some other control information (stored in the
36-
<filename>pg_control</> file). This function is sometimes needed
36+
optionally resets some other control information stored in the
37+
<filename>pg_control</> file. This function is sometimes needed
3738
if these files have become corrupted. It should be used only as a
3839
last resort, when the server will not start due to such corruption.
3940
</para>
@@ -60,8 +61,9 @@ PostgreSQL documentation
6061
by specifying the <literal>-f</> (force) switch. In this case plausible
6162
values will be substituted for the missing data. Most of the fields can be
6263
expected to match, but manual assistance may be needed for the next OID,
63-
next transaction ID, WAL starting address, and database locale fields.
64-
The first three of these can be set using the switches discussed below.
64+
next transaction ID, next multi-transaction ID and offset,
65+
WAL starting address, and database locale fields.
66+
The first five of these can be set using the switches discussed below.
6567
<command>pg_resetxlog</command>'s own environment is the source for its
6668
guess at the locale fields; take care that <envar>LANG</> and so forth
6769
match the environment that <command>initdb</> was run in.
@@ -74,9 +76,10 @@ PostgreSQL documentation
7476
</para>
7577

7678
<para>
77-
The <literal>-o</>, <literal>-x</>, <literal>-m</>, and <literal>-l</>
79+
The <literal>-o</>, <literal>-x</>, <literal>-m</>, <literal>-O</>,
80+
and <literal>-l</>
7881
switches allow the next OID, next transaction ID, next multi-transaction
79-
ID, and WAL starting address values to
82+
ID, next multi-transaction offset, and WAL starting address values to
8083
be set manually. These are only needed when
8184
<command>pg_resetxlog</command> is unable to determine appropriate values
8285
by reading <filename>pg_control</>. Safe values may be determined as
@@ -108,6 +111,17 @@ PostgreSQL documentation
108111
</para>
109112
</listitem>
110113

114+
<listitem>
115+
<para>
116+
A safe value for the next multi-transaction offset (<literal>-O</>)
117+
may be determined by looking for the numerically largest
118+
file name in the directory <filename>pg_multixact/members</> under the
119+
data directory, adding one, and then multiplying by 65536. As above,
120+
the file names are in hexadecimal, so the easiest way to do this is to
121+
specify the switch value in hexadecimal and add four zeroes.
122+
</para>
123+
</listitem>
124+
111125
<listitem>
112126
<para>
113127
The WAL starting address (<literal>-l</>) should be

src/backend/access/heap/heapam.c

Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
*
99
*
1010
* IDENTIFICATION
11-
* $PostgreSQL: pgsql/src/backend/access/heap/heapam.c,v 1.193 2005/06/06 20:22:56 tgl Exp $
11+
* $PostgreSQL: pgsql/src/backend/access/heap/heapam.c,v 1.194 2005/06/08 15:50:21 tgl Exp $
1212
*
1313
*
1414
* INTERFACE ROUTINES
@@ -2219,6 +2219,8 @@ heap_lock_tuple(Relation relation, HeapTuple tuple, Buffer *buffer,
22192219
* Else the same IDs might be re-used after a crash, which would be
22202220
* disastrous if this page made it to disk before the crash. Essentially
22212221
* we have to enforce the WAL log-before-data rule even in this case.
2222+
* (Also, in a PITR log-shipping or 2PC environment, we have to have XLOG
2223+
* entries for everything anyway.)
22222224
*/
22232225
if (!relation->rd_istemp)
22242226
{
@@ -2228,6 +2230,8 @@ heap_lock_tuple(Relation relation, HeapTuple tuple, Buffer *buffer,
22282230

22292231
xlrec.target.node = relation->rd_node;
22302232
xlrec.target.tid = tuple->t_self;
2233+
xlrec.locking_xid = xid;
2234+
xlrec.xid_is_mxact = ((new_infomask & HEAP_XMAX_IS_MULTI) != 0);
22312235
xlrec.shared_lock = (mode == LockTupleShared);
22322236
rdata[0].data = (char *) &xlrec;
22332237
rdata[0].len = SizeOfHeapLock;
@@ -2900,17 +2904,18 @@ heap_xlog_lock(XLogRecPtr lsn, XLogRecord *record)
29002904

29012905
htup = (HeapTupleHeader) PageGetItem(page, lp);
29022906

2903-
/*
2904-
* Presently, we don't bother to restore the locked state, but
2905-
* just set the XMAX_INVALID bit.
2906-
*/
29072907
htup->t_infomask &= ~(HEAP_XMAX_COMMITTED |
29082908
HEAP_XMAX_INVALID |
29092909
HEAP_XMAX_IS_MULTI |
29102910
HEAP_IS_LOCKED |
29112911
HEAP_MOVED);
2912-
htup->t_infomask |= HEAP_XMAX_INVALID;
2913-
HeapTupleHeaderSetXmax(htup, record->xl_xid);
2912+
if (xlrec->xid_is_mxact)
2913+
htup->t_infomask |= HEAP_XMAX_IS_MULTI;
2914+
if (xlrec->shared_lock)
2915+
htup->t_infomask |= HEAP_XMAX_SHARED_LOCK;
2916+
else
2917+
htup->t_infomask |= HEAP_XMAX_EXCL_LOCK;
2918+
HeapTupleHeaderSetXmax(htup, xlrec->locking_xid);
29142919
HeapTupleHeaderSetCmax(htup, FirstCommandId);
29152920
/* Make sure there is no forward chain link in t_ctid */
29162921
htup->t_ctid = xlrec->target.tid;
@@ -3010,6 +3015,11 @@ heap_desc(char *buf, uint8 xl_info, char *rec)
30103015
strcat(buf, "shared_lock: ");
30113016
else
30123017
strcat(buf, "exclusive_lock: ");
3018+
if (xlrec->xid_is_mxact)
3019+
strcat(buf, "mxid ");
3020+
else
3021+
strcat(buf, "xid ");
3022+
sprintf(buf + strlen(buf), "%u ", xlrec->locking_xid);
30133023
out_target(buf, &(xlrec->target));
30143024
}
30153025
else

0 commit comments

Comments
 (0)