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

Commit5c2d36c

Browse files
committed
Code review for latest changes.
1 parentc6fdf8b commit5c2d36c

File tree

2 files changed

+29
-34
lines changed

2 files changed

+29
-34
lines changed

‎contrib/pg_resetxlog/README.pg_resetxlog

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ module pg_controldata and run it to be sure the DB state is SHUTDOWN).
2121
Then run pg_resetxlog, and finally install and start the new version of
2222
the database software.
2323

24-
A tertiary purposeit its use by pg_upgrade to set the next transaction
24+
A tertiary purposeis its use by pg_upgrade to set the next transaction
2525
id and checkpoint location in pg_control.
2626

2727
To run the program, make sure your postmaster is not running, then

‎contrib/pg_resetxlog/pg_resetxlog.c

Lines changed: 28 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
* Portions Copyright (c) 1996-2001, PostgreSQL Global Development Group
2424
* Portions Copyright (c) 1994, Regents of the University of California
2525
*
26-
* $Header: /cvsroot/pgsql/contrib/pg_resetxlog/Attic/pg_resetxlog.c,v 1.16 2002/01/1106:33:01 momjian Exp $
26+
* $Header: /cvsroot/pgsql/contrib/pg_resetxlog/Attic/pg_resetxlog.c,v 1.17 2002/01/1121:27:13 tgl Exp $
2727
*
2828
*-------------------------------------------------------------------------
2929
*/
@@ -63,7 +63,6 @@
6363
snprintf(path, MAXPGPATH, "%s/%08X%08X",\
6464
XLogDir, log, seg)
6565

66-
6766
/******************** end of stuff copied from xlog.c ********************/
6867

6968

@@ -134,7 +133,7 @@ ReadControlFile(void)
134133
return true;
135134
}
136135

137-
fprintf(stderr,"pg_control exists but has invalid CRC;proceeding with caution.\n");
136+
fprintf(stderr,"pg_control exists but has invalid CRC;proceed with caution.\n");
138137
/* We will use the data anyway, but treat it as guessed. */
139138
memcpy(&ControlFile,buffer,sizeof(ControlFile));
140139
guessed= true;
@@ -218,12 +217,11 @@ GuessControlValues(void)
218217
staticvoid
219218
PrintControlValues(boolguessed)
220219
{
221-
printf("\n%spg_control values:\n\n"
220+
printf("%spg_control values:\n\n"
222221
"pg_control version number: %u\n"
223222
"Catalog version number: %u\n"
224223
"Current log file id: %u\n"
225224
"Next log file segment: %u\n"
226-
"Latest checkpoint location: %X/%X\n"
227225
"Latest checkpoint's StartUpID: %u\n"
228226
"Latest checkpoint's NextXID: %u\n"
229227
"Latest checkpoint's NextOID: %u\n"
@@ -237,8 +235,6 @@ PrintControlValues(bool guessed)
237235
ControlFile.catalog_version_no,
238236
ControlFile.logId,
239237
ControlFile.logSeg,
240-
ControlFile.checkPoint.xlogid,
241-
ControlFile.checkPoint.xrecoff,
242238
ControlFile.checkPointCopy.ThisStartUpID,
243239
ControlFile.checkPointCopy.nextXid,
244240
ControlFile.checkPointCopy.nextOid,
@@ -253,7 +249,7 @@ PrintControlValues(bool guessed)
253249
* Write out the new pg_control file.
254250
*/
255251
staticvoid
256-
RewriteControlFile(TransactionIdset_xid,XLogRecPtrset_checkpoint)
252+
RewriteControlFile(void)
257253
{
258254
intfd;
259255
charbuffer[BLCKSZ];/* need not be aligned */
@@ -277,18 +273,10 @@ RewriteControlFile(TransactionId set_xid, XLogRecPtr set_checkpoint)
277273
ControlFile.time=time(NULL);
278274
ControlFile.logId=newXlogId;
279275
ControlFile.logSeg=newXlogSeg+1;
276+
ControlFile.checkPoint=ControlFile.checkPointCopy.redo;
280277
ControlFile.prevCheckPoint.xlogid=0;
281278
ControlFile.prevCheckPoint.xrecoff=0;
282279

283-
if (set_xid!=0)
284-
ControlFile.checkPointCopy.nextXid=set_xid;
285-
286-
if (set_checkpoint.xlogid==0&&
287-
set_checkpoint.xrecoff==0)
288-
ControlFile.checkPoint=ControlFile.checkPointCopy.redo;
289-
else
290-
ControlFile.checkPoint=set_checkpoint;
291-
292280
/* Contents are protected with a CRC */
293281
INIT_CRC64(ControlFile.crc);
294282
COMP_CRC64(ControlFile.crc,
@@ -478,11 +466,11 @@ WriteEmptyXLOG(void)
478466
staticvoid
479467
usage(void)
480468
{
481-
fprintf(stderr,"Usage: pg_resetxlog [-f] [-n] [-x xid] [ -llog_id offset ] PGDataDirectory\n"
482-
" -f\t force update to be done\n"
483-
" -n\t no update, just show extracted pg_control values (for testing)\n"
484-
" -xXID set XID in pg_control\n"
485-
" -llog_id offset set hex checkpointlocationin pg_control\n");
469+
fprintf(stderr,"Usage: pg_resetxlog [-f] [-n] [-x xid] [ -lfileid seg ] PGDataDirectory\n"
470+
" -f\t\tforce update to be done\n"
471+
" -n\t\tno update, just show extracted pg_control values (for testing)\n"
472+
" -xxid\tset next transaction ID\n"
473+
" -lfileid seg\tforce minimum WAL startinglocationfor new xlog\n");
486474
exit(1);
487475
}
488476

@@ -494,7 +482,8 @@ main(int argc, char **argv)
494482
boolforce= false;
495483
boolnoupdate= false;
496484
TransactionIdset_xid=0;
497-
XLogRecPtrset_checkpoint= {0,0};
485+
uint32minXlogId=0,
486+
minXlogSeg=0;
498487
intfd;
499488
charpath[MAXPGPATH];
500489

@@ -514,7 +503,7 @@ main(int argc, char **argv)
514503
set_xid=strtoul(argv[argn],NULL,0);
515504
if (set_xid==0)
516505
{
517-
fprintf(stderr,"XID can not be 0.");
506+
fprintf(stderr,"XID can not be 0.\n");
518507
exit(1);
519508
}
520509
}
@@ -523,17 +512,11 @@ main(int argc, char **argv)
523512
argn++;
524513
if (argn==argc)
525514
usage();
526-
set_checkpoint.xlogid=strtoul(argv[argn],NULL,16);
515+
minXlogId=strtoul(argv[argn],NULL,0);
527516
argn++;
528517
if (argn==argc)
529518
usage();
530-
set_checkpoint.xrecoff=strtoul(argv[argn],NULL,16);
531-
if (set_checkpoint.xlogid==0&&
532-
set_checkpoint.xrecoff==0)
533-
{
534-
fprintf(stderr,"Checkpoint can not be '0 0'.");
535-
exit(1);
536-
}
519+
minXlogSeg=strtoul(argv[argn],NULL,0);
537520
}
538521
else
539522
usage();
@@ -606,8 +589,20 @@ main(int argc, char **argv)
606589

607590
/*
608591
* Else, do the dirty deed.
592+
*
593+
* First adjust fields if required by switches.
609594
*/
610-
RewriteControlFile(set_xid,set_checkpoint);
595+
if (set_xid!=0)
596+
ControlFile.checkPointCopy.nextXid=set_xid;
597+
598+
if (minXlogId>ControlFile.logId||
599+
(minXlogId==ControlFile.logId&&minXlogSeg>ControlFile.logSeg))
600+
{
601+
ControlFile.logId=minXlogId;
602+
ControlFile.logSeg=minXlogSeg;
603+
}
604+
605+
RewriteControlFile();
611606
KillExistingXLOG();
612607
WriteEmptyXLOG();
613608

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp