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

Commitf6e603c

Browse files
committed
Add new -x XID option to /contrib/pg_resetxlog for future pg_upgrade use.
1 parent7955f98 commitf6e603c

File tree

2 files changed

+65
-29
lines changed

2 files changed

+65
-29
lines changed

‎contrib/pg_resetxlog/README.pg_resetxlog

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,9 @@ 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 purpose it its use by pg_upgrade to set the next transaction
25+
id in pg_control.
26+
2427
To run the program, make sure your postmaster is not running, then
2528
(as the Postgres admin user) do
2629

‎contrib/pg_resetxlog/pg_resetxlog.c

Lines changed: 62 additions & 29 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.10 2001/11/05 17:46:23 momjian Exp $
26+
* $Header: /cvsroot/pgsql/contrib/pg_resetxlog/Attic/pg_resetxlog.c,v 1.11 2002/01/10 17:51:52 momjian Exp $
2727
*
2828
*-------------------------------------------------------------------------
2929
*/
@@ -709,34 +709,39 @@ PrintControlValues(void)
709709
* Write out the new pg_control file.
710710
*/
711711
staticvoid
712-
RewriteControlFile(void)
712+
RewriteControlFile(TransactionIdset_xid)
713713
{
714714
intfd;
715715
charbuffer[BLCKSZ];/* need not be aligned */
716716

717-
/*
718-
* Adjust fields as needed to force an empty XLOG starting at the next
719-
* available segment.
720-
*/
721-
newXlogId=ControlFile.logId;
722-
newXlogSeg=ControlFile.logSeg;
723-
/* be sure we wrap around correctly at end of a logfile */
724-
NextLogSeg(newXlogId,newXlogSeg);
725-
726-
ControlFile.checkPointCopy.redo.xlogid=newXlogId;
727-
ControlFile.checkPointCopy.redo.xrecoff=
728-
newXlogSeg*XLogSegSize+SizeOfXLogPHD;
729-
ControlFile.checkPointCopy.undo=ControlFile.checkPointCopy.redo;
730-
ControlFile.checkPointCopy.time=time(NULL);
731-
732-
ControlFile.state=DB_SHUTDOWNED;
733-
ControlFile.time=time(NULL);
734-
ControlFile.logId=newXlogId;
735-
ControlFile.logSeg=newXlogSeg+1;
736-
ControlFile.checkPoint=ControlFile.checkPointCopy.redo;
737-
ControlFile.prevCheckPoint.xlogid=0;
738-
ControlFile.prevCheckPoint.xrecoff=0;
739-
717+
if (set_xid==0)
718+
{
719+
/*
720+
* Adjust fields as needed to force an empty XLOG starting at the next
721+
* available segment.
722+
*/
723+
newXlogId=ControlFile.logId;
724+
newXlogSeg=ControlFile.logSeg;
725+
/* be sure we wrap around correctly at end of a logfile */
726+
NextLogSeg(newXlogId,newXlogSeg);
727+
728+
ControlFile.checkPointCopy.redo.xlogid=newXlogId;
729+
ControlFile.checkPointCopy.redo.xrecoff=
730+
newXlogSeg*XLogSegSize+SizeOfXLogPHD;
731+
ControlFile.checkPointCopy.undo=ControlFile.checkPointCopy.redo;
732+
ControlFile.checkPointCopy.time=time(NULL);
733+
734+
ControlFile.state=DB_SHUTDOWNED;
735+
ControlFile.time=time(NULL);
736+
ControlFile.logId=newXlogId;
737+
ControlFile.logSeg=newXlogSeg+1;
738+
ControlFile.checkPoint=ControlFile.checkPointCopy.redo;
739+
ControlFile.prevCheckPoint.xlogid=0;
740+
ControlFile.prevCheckPoint.xrecoff=0;
741+
}
742+
else
743+
ControlFile.checkPointCopy.nextXid=set_xid;
744+
740745
/* Contents are protected with a CRC */
741746
INIT_CRC64(ControlFile.crc);
742747
COMP_CRC64(ControlFile.crc,
@@ -926,9 +931,10 @@ WriteEmptyXLOG(void)
926931
staticvoid
927932
usage(void)
928933
{
929-
fprintf(stderr,"Usage: pg_resetxlog [-f] [-n] PGDataDirectory\n\n"
930-
" -f\tforce update to be done\n"
931-
" -n\tno update, just show extracted pg_control values (for testing)\n");
934+
fprintf(stderr,"Usage: pg_resetxlog [-f] [-n] [-x xid] PGDataDirectory\n"
935+
" -f\tforce update to be done\n"
936+
" -n\tno update, just show extracted pg_control values (for testing)\n"
937+
" -x XID\tset XID in pg_control\n");
932938
exit(1);
933939
}
934940

@@ -939,6 +945,7 @@ main(int argc, char **argv)
939945
intargn;
940946
boolforce= false;
941947
boolnoupdate= false;
948+
TransactionIdset_xid=0;
942949
intfd;
943950
charpath[MAXPGPATH];
944951

@@ -950,6 +957,18 @@ main(int argc, char **argv)
950957
force= true;
951958
elseif (strcmp(argv[argn],"-n")==0)
952959
noupdate= true;
960+
elseif (strcmp(argv[argn],"-x")==0)
961+
{
962+
argn++;
963+
if (argn==argc)
964+
usage();
965+
set_xid=strtoul(argv[argn],NULL,0);
966+
if (set_xid==0)
967+
{
968+
fprintf(stderr,"XID can not be 0.");
969+
exit(1);
970+
}
971+
}
953972
else
954973
usage();
955974
}
@@ -992,6 +1011,20 @@ main(int argc, char **argv)
9921011
if (!ReadControlFile())
9931012
GuessControlValues();
9941013

1014+
/*
1015+
* Set XID in pg_control and exit
1016+
*/
1017+
if (set_xid)
1018+
{
1019+
if (guessed)
1020+
{
1021+
printf("\npg_control appears corrupt. Can not update XID.\n");
1022+
exit(1);
1023+
}
1024+
RewriteControlFile(set_xid);
1025+
exit(0);
1026+
}
1027+
9951028
/*
9961029
* If we had to guess anything, and -f was not given, just print the
9971030
* guessed values and exit. Also print if -n is given.
@@ -1018,7 +1051,7 @@ main(int argc, char **argv)
10181051
/*
10191052
* Else, do the dirty deed.
10201053
*/
1021-
RewriteControlFile();
1054+
RewriteControlFile(0);
10221055
KillExistingXLOG();
10231056
WriteEmptyXLOG();
10241057

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp