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.12 2002/01/1018:08:29 momjian Exp $
26+ * $Header: /cvsroot/pgsql/contrib/pg_resetxlog/Attic/pg_resetxlog.c,v 1.13 2002/01/1020:09:06 momjian Exp $
2727 *
2828 *-------------------------------------------------------------------------
2929 */
@@ -683,6 +683,7 @@ PrintControlValues(void)
683683"Catalog version number: %u\n"
684684"Current log file id: %u\n"
685685"Next log file segment: %u\n"
686+ "Latest checkpoint location: %X/%X\n"
686687"Latest checkpoint's StartUpID: %u\n"
687688"Latest checkpoint's NextXID: %u\n"
688689"Latest checkpoint's NextOID: %u\n"
@@ -695,6 +696,8 @@ PrintControlValues(void)
695696ControlFile .catalog_version_no ,
696697ControlFile .logId ,
697698ControlFile .logSeg ,
699+ ControlFile .checkPoint .xlogid ,
700+ ControlFile .checkPoint .xrecoff ,
698701ControlFile .checkPointCopy .ThisStartUpID ,
699702ControlFile .checkPointCopy .nextXid ,
700703ControlFile .checkPointCopy .nextOid ,
@@ -709,7 +712,7 @@ PrintControlValues(void)
709712 * Write out the new pg_control file.
710713 */
711714static void
712- RewriteControlFile (TransactionId set_xid )
715+ RewriteControlFile (TransactionId set_xid , XLogRecPtr set_checkpoint )
713716{
714717int fd ;
715718char buffer [BLCKSZ ];/* need not be aligned */
@@ -733,13 +736,18 @@ RewriteControlFile(TransactionId set_xid)
733736ControlFile .time = time (NULL );
734737ControlFile .logId = newXlogId ;
735738ControlFile .logSeg = newXlogSeg + 1 ;
736- ControlFile .checkPoint = ControlFile .checkPointCopy .redo ;
737739ControlFile .prevCheckPoint .xlogid = 0 ;
738740ControlFile .prevCheckPoint .xrecoff = 0 ;
739741
740742if (set_xid != 0 )
741743ControlFile .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+
743751/* Contents are protected with a CRC */
744752INIT_CRC64 (ControlFile .crc );
745753COMP_CRC64 (ControlFile .crc ,
@@ -929,10 +937,11 @@ WriteEmptyXLOG(void)
929937static void
930938usage (void )
931939{
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" );
936945exit (1 );
937946}
938947
@@ -944,6 +953,7 @@ main(int argc, char **argv)
944953bool force = false;
945954bool noupdate = false;
946955TransactionId set_xid = 0 ;
956+ XLogRecPtr set_checkpoint = {0 ,0 };
947957int fd ;
948958char path [MAXPGPATH ];
949959
@@ -967,6 +977,23 @@ main(int argc, char **argv)
967977exit (1 );
968978}
969979}
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+ }
970997else
971998usage ();
972999}
@@ -1035,7 +1062,7 @@ main(int argc, char **argv)
10351062/*
10361063 * Else, do the dirty deed.
10371064 */
1038- RewriteControlFile (set_xid );
1065+ RewriteControlFile (set_xid , set_checkpoint );
10391066KillExistingXLOG ();
10401067WriteEmptyXLOG ();
10411068