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

Commit 59bffa3

Browse files
committed
Adjust pg_resetxlog to handle 8.0 WAL file names properly.
1 parent 8562b03 commit 59bffa3

File tree

2 files changed

+35
-15
lines changed

2 files changed

+35
-15
lines changed

doc/src/sgml/ref/pg_resetxlog.sgml

Lines changed: 15 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.8 2003/11/29 19:51:39 pgsql Exp $
2+
$PostgreSQL: pgsql/doc/src/sgml/ref/pg_resetxlog.sgml,v 1.9 2004/12/20 01:42:09 tgl Exp $
33
PostgreSQL documentation
44
-->
55

@@ -22,7 +22,7 @@ PostgreSQL documentation
2222
<arg> -n </arg>
2323
<arg> -o <replaceable class="parameter">oid</replaceable> </arg>
2424
<arg> -x <replaceable class="parameter">xid</replaceable> </arg>
25-
<arg> -l <replaceable class="parameter">fileid</replaceable>,<replaceable class="parameter">seg</replaceable> </arg>
25+
<arg> -l <replaceable class="parameter">timelineid</replaceable>,<replaceable class="parameter">fileid</replaceable>,<replaceable class="parameter">seg</replaceable> </arg>
2626
<arg choice="plain"><replaceable>datadir</replaceable></arg>
2727
</cmdsynopsis>
2828
</refsynopsisdiv>
@@ -79,17 +79,25 @@ PostgreSQL documentation
7979
<command>pg_resetxlog</command> is unable to determine appropriate values
8080
by reading <filename>pg_control</>. A safe value for the
8181
next transaction ID may be determined by looking for the numerically largest
82-
file name in the directory <filename>pg_clog</> under the data directory, adding one,
82+
file name in the directory <filename>pg_clog</> under the data directory,
83+
adding one,
8384
and then multiplying by 1048576. Note that the file names are in
8485
hexadecimal. It is usually easiest to specify the switch value in
8586
hexadecimal too. For example, if <filename>0011</> is the largest entry
8687
in <filename>pg_clog</>, <literal>-x 0x1200000</> will work (five trailing
8788
zeroes provide the proper multiplier).
8889
The WAL starting address should be
89-
larger than any file number currently existing in
90-
the directory <filename>pg_xlog</> under the data directory. The addresses are also in hexadecimal and
91-
have two parts. For example, if <filename>000000FF0000003A</> is the
92-
largest entry in <filename>pg_xlog</>, <literal>-l 0xFF,0x3B</> will work.
90+
larger than any file name currently existing in
91+
the directory <filename>pg_xlog</> under the data directory.
92+
These names are also in hexadecimal and have three parts. The first
93+
part is the <quote>timeline ID</> and should usually be kept the same.
94+
Do not choose a value larger than 255 (<literal>0xFF</>) for the third
95+
part; instead increment the second part and reset the third part to 0.
96+
For example, if <filename>00000001000000320000004A</> is the
97+
largest entry in <filename>pg_xlog</>, <literal>-l 0x1,0x32,0x4B</> will
98+
work; but if the largest entry is
99+
<filename>000000010000003A000000FF</>, choose <literal>-l 0x1,0x3B,0x0</>
100+
or more.
93101
There is no comparably easy way to determine a next OID that's beyond
94102
the largest one in the database, but fortunately it is not critical to
95103
get the next-OID setting right.

src/bin/pg_resetxlog/pg_resetxlog.c

Lines changed: 20 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
* Portions Copyright (c) 1996-2004, PostgreSQL Global Development Group
2424
* Portions Copyright (c) 1994, Regents of the University of California
2525
*
26-
* $PostgreSQL: pgsql/src/bin/pg_resetxlog/pg_resetxlog.c,v 1.26 2004/12/14 01:59:41 neilc Exp $
26+
* $PostgreSQL: pgsql/src/bin/pg_resetxlog/pg_resetxlog.c,v 1.27 2004/12/20 01:42:11 tgl Exp $
2727
*
2828
*-------------------------------------------------------------------------
2929
*/
@@ -77,10 +77,12 @@ main(int argc, char *argv[])
7777
bool noupdate = false;
7878
TransactionId set_xid = 0;
7979
Oid set_oid = 0;
80-
uint32 minXlogId = 0,
80+
uint32 minXlogTli = 0,
81+
minXlogId = 0,
8182
minXlogSeg = 0;
8283
char *endptr;
8384
char *endptr2;
85+
char *endptr3;
8486
char *DataDir;
8587
int fd;
8688
char path[MAXPGPATH];
@@ -147,15 +149,22 @@ main(int argc, char *argv[])
147149
break;
148150

149151
case 'l':
150-
minXlogId = strtoul(optarg, &endptr, 0);
152+
minXlogTli = strtoul(optarg, &endptr, 0);
151153
if (endptr == optarg || *endptr != ',')
152154
{
153155
fprintf(stderr, _("%s: invalid argument for option -l\n"), progname);
154156
fprintf(stderr, _("Try \"%s --help\" for more information.\n"), progname);
155157
exit(1);
156158
}
157-
minXlogSeg = strtoul(endptr + 1, &endptr2, 0);
158-
if (endptr2 == endptr + 1 || *endptr2 != '\0')
159+
minXlogId = strtoul(endptr + 1, &endptr2, 0);
160+
if (endptr2 == endptr + 1 || *endptr2 != ',')
161+
{
162+
fprintf(stderr, _("%s: invalid argument for option -l\n"), progname);
163+
fprintf(stderr, _("Try \"%s --help\" for more information.\n"), progname);
164+
exit(1);
165+
}
166+
minXlogSeg = strtoul(endptr2 + 1, &endptr3, 0);
167+
if (endptr3 == endptr2 + 1 || *endptr3 != '\0')
159168
{
160169
fprintf(stderr, _("%s: invalid argument for option -l\n"), progname);
161170
fprintf(stderr, _("Try \"%s --help\" for more information.\n"), progname);
@@ -238,6 +247,9 @@ main(int argc, char *argv[])
238247
if (set_oid != 0)
239248
ControlFile.checkPointCopy.nextOid = set_oid;
240249

250+
if (minXlogTli > ControlFile.checkPointCopy.ThisTimeLineID)
251+
ControlFile.checkPointCopy.ThisTimeLineID = minXlogTli;
252+
241253
if (minXlogId > ControlFile.logId ||
242254
(minXlogId == ControlFile.logId &&
243255
minXlogSeg > ControlFile.logSeg))
@@ -597,8 +609,8 @@ KillExistingXLOG(void)
597609
errno = 0;
598610
while ((xlde = readdir(xldir)) != NULL)
599611
{
600-
if (strlen(xlde->d_name) == 16 &&
601-
strspn(xlde->d_name, "0123456789ABCDEF") == 16)
612+
if (strlen(xlde->d_name) == 24 &&
613+
strspn(xlde->d_name, "0123456789ABCDEF") == 24)
602614
{
603615
snprintf(path, MAXPGPATH, "%s/%s", XLogDir, xlde->d_name);
604616
if (unlink(path) < 0)
@@ -739,7 +751,7 @@ usage(void)
739751
printf(_("Usage:\n %s [OPTION]... DATADIR\n\n"), progname);
740752
printf(_("Options:\n"));
741753
printf(_(" -f force update to be done\n"));
742-
printf(_(" -l FILEID,SEG force minimum WAL starting location for new transaction log\n"));
754+
printf(_(" -l TLI,FILE,SEG force minimum WAL starting location for new transaction log\n"));
743755
printf(_(" -n no update, just show extracted control values (for testing)\n"));
744756
printf(_(" -o OID set next OID\n"));
745757
printf(_(" -x XID set next transaction ID\n"));

0 commit comments

Comments
 (0)