23
23
* Portions Copyright (c) 1996-2001, PostgreSQL Global Development Group
24
24
* Portions Copyright (c) 1994, Regents of the University of California
25
25
*
26
- * $Header: /cvsroot/pgsql/contrib/pg_resetxlog/Attic/pg_resetxlog.c,v 1.12 2002/01/10 18:08:29 momjian Exp $
26
+ * $Header: /cvsroot/pgsql/contrib/pg_resetxlog/Attic/pg_resetxlog.c,v 1.13 2002/01/10 20:09:06 momjian Exp $
27
27
*
28
28
*-------------------------------------------------------------------------
29
29
*/
@@ -683,6 +683,7 @@ PrintControlValues(void)
683
683
"Catalog version number: %u\n"
684
684
"Current log file id: %u\n"
685
685
"Next log file segment: %u\n"
686
+ "Latest checkpoint location: %X/%X\n"
686
687
"Latest checkpoint's StartUpID: %u\n"
687
688
"Latest checkpoint's NextXID: %u\n"
688
689
"Latest checkpoint's NextOID: %u\n"
@@ -695,6 +696,8 @@ PrintControlValues(void)
695
696
ControlFile .catalog_version_no ,
696
697
ControlFile .logId ,
697
698
ControlFile .logSeg ,
699
+ ControlFile .checkPoint .xlogid ,
700
+ ControlFile .checkPoint .xrecoff ,
698
701
ControlFile .checkPointCopy .ThisStartUpID ,
699
702
ControlFile .checkPointCopy .nextXid ,
700
703
ControlFile .checkPointCopy .nextOid ,
@@ -709,7 +712,7 @@ PrintControlValues(void)
709
712
* Write out the new pg_control file.
710
713
*/
711
714
static void
712
- RewriteControlFile (TransactionId set_xid )
715
+ RewriteControlFile (TransactionId set_xid , XLogRecPtr set_checkpoint )
713
716
{
714
717
int fd ;
715
718
char buffer [BLCKSZ ]; /* need not be aligned */
@@ -733,13 +736,18 @@ RewriteControlFile(TransactionId set_xid)
733
736
ControlFile .time = time (NULL );
734
737
ControlFile .logId = newXlogId ;
735
738
ControlFile .logSeg = newXlogSeg + 1 ;
736
- ControlFile .checkPoint = ControlFile .checkPointCopy .redo ;
737
739
ControlFile .prevCheckPoint .xlogid = 0 ;
738
740
ControlFile .prevCheckPoint .xrecoff = 0 ;
739
741
740
742
if (set_xid != 0 )
741
743
ControlFile .checkPointCopy .nextXid = set_xid ;
742
-
744
+
745
+ if (set_checkpoint .xlogid == 0 &&
746
+ set_checkpoint .xrecoff == 0 )
747
+ ControlFile .checkPoint = ControlFile .checkPointCopy .redo ;
748
+ else
749
+ ControlFile .checkPoint = set_checkpoint ;
750
+
743
751
/* Contents are protected with a CRC */
744
752
INIT_CRC64 (ControlFile .crc );
745
753
COMP_CRC64 (ControlFile .crc ,
@@ -929,10 +937,11 @@ WriteEmptyXLOG(void)
929
937
static void
930
938
usage (void )
931
939
{
932
- fprintf (stderr , "Usage: pg_resetxlog [-f] [-n] [-x xid] PGDataDirectory\n"
933
- " -f\tforce update to be done\n"
934
- " -n\tno update, just show extracted pg_control values (for testing)\n"
935
- " -x XID\tset XID in pg_control\n" );
940
+ fprintf (stderr , "Usage: pg_resetxlog [-f] [-n] [-x xid] [ -l log_id offset ] PGDataDirectory\n"
941
+ " -f\t force update to be done\n"
942
+ " -n\t no update, just show extracted pg_control values (for testing)\n"
943
+ " -x XID set XID in pg_control\n"
944
+ " -l log_id offset set checkpoint location in pg_control\n" );
936
945
exit (1 );
937
946
}
938
947
@@ -944,6 +953,7 @@ main(int argc, char **argv)
944
953
bool force = false;
945
954
bool noupdate = false;
946
955
TransactionId set_xid = 0 ;
956
+ XLogRecPtr set_checkpoint = {0 ,0 };
947
957
int fd ;
948
958
char path [MAXPGPATH ];
949
959
@@ -967,6 +977,23 @@ main(int argc, char **argv)
967
977
exit (1 );
968
978
}
969
979
}
980
+ else if (strcmp (argv [argn ], "-l" ) == 0 )
981
+ {
982
+ argn ++ ;
983
+ if (argn == argc )
984
+ usage ();
985
+ set_checkpoint .xlogid = strtoul (argv [argn ], NULL , 0 );
986
+ argn ++ ;
987
+ if (argn == argc )
988
+ usage ();
989
+ set_checkpoint .xrecoff = strtoul (argv [argn ], NULL , 0 );
990
+ if (set_checkpoint .xlogid == 0 &&
991
+ set_checkpoint .xrecoff == 0 )
992
+ {
993
+ fprintf (stderr , "Checkpoint can not be '0 0'." );
994
+ exit (1 );
995
+ }
996
+ }
970
997
else
971
998
usage ();
972
999
}
@@ -1035,7 +1062,7 @@ main(int argc, char **argv)
1035
1062
/*
1036
1063
* Else, do the dirty deed.
1037
1064
*/
1038
- RewriteControlFile (set_xid );
1065
+ RewriteControlFile (set_xid , set_checkpoint );
1039
1066
KillExistingXLOG ();
1040
1067
WriteEmptyXLOG ();
1041
1068
0 commit comments