12
12
* by scanning the old xlog if necessary.
13
13
* 3. Modify pg_control to reflect a "shutdown" state with a checkpoint
14
14
* record at the start of xlog.
15
- * 4. Flush the existing xlog files and write a new segment 0 with
16
- * just a checkpoint record in it.
15
+ * 4. Flush the existing xlog files and write a new segment with
16
+ * just a checkpoint record in it. The new segment is positioned
17
+ * just past the end of the old xlog, so that existing LSNs in
18
+ * data pages will appear to be "in the past".
17
19
* This is all pretty straightforward except for the intuition part of
18
20
* step 2 ...
19
21
*
20
22
*
21
23
* Portions Copyright (c) 1996-2001, PostgreSQL Global Development Group
22
24
* Portions Copyright (c) 1994, Regents of the University of California
23
25
*
24
- * $Header: /cvsroot/pgsql/contrib/pg_resetxlog/Attic/pg_resetxlog.c,v 1.1 2001/03/14 00:57:43 tgl Exp $
26
+ * $Header: /cvsroot/pgsql/contrib/pg_resetxlog/Attic/pg_resetxlog.c,v 1.2 2001/03/16 05:08:39 tgl Exp $
25
27
*
26
28
*-------------------------------------------------------------------------
27
29
*/
@@ -108,6 +110,7 @@ static char XLogDir[MAXPGPATH];
108
110
static char ControlFilePath [MAXPGPATH ];
109
111
110
112
static ControlFileData ControlFile ; /* pg_control values */
113
+ static uint32 newXlogId , newXlogSeg ; /* ID/Segment of new XLOG segment */
111
114
static bool guessed = false; /* T if we had to guess at any values */
112
115
113
116
@@ -390,6 +393,8 @@ CheckControlVersion0(char *buffer, int len)
390
393
ControlFile .catalog_version_no = oldfile -> catalog_version_no ;
391
394
392
395
ControlFile .state = oldfile -> state ;
396
+ ControlFile .logId = oldfile -> logId ;
397
+ ControlFile .logSeg = oldfile -> logSeg ;
393
398
394
399
ControlFile .blcksz = oldfile -> blcksz ;
395
400
ControlFile .relseg_size = oldfile -> relseg_size ;
@@ -671,6 +676,8 @@ PrintControlValues(void)
671
676
printf ("Guessed-at pg_control values:\n\n"
672
677
"pg_control version number: %u\n"
673
678
"Catalog version number: %u\n"
679
+ "Current log file id: %u\n"
680
+ "Next log file segment: %u\n"
674
681
"Latest checkpoint's StartUpID: %u\n"
675
682
"Latest checkpoint's NextXID: %u\n"
676
683
"Latest checkpoint's NextOID: %u\n"
@@ -681,6 +688,8 @@ PrintControlValues(void)
681
688
682
689
ControlFile .pg_control_version ,
683
690
ControlFile .catalog_version_no ,
691
+ ControlFile .logId ,
692
+ ControlFile .logSeg ,
684
693
ControlFile .checkPointCopy .ThisStartUpID ,
685
694
ControlFile .checkPointCopy .nextXid ,
686
695
ControlFile .checkPointCopy .nextOid ,
@@ -701,17 +710,24 @@ RewriteControlFile(void)
701
710
char buffer [BLCKSZ ]; /* need not be aligned */
702
711
703
712
/*
704
- * Adjust fields as needed to force an empty XLOG.
713
+ * Adjust fields as needed to force an empty XLOG starting at the
714
+ * next available segment.
705
715
*/
706
- ControlFile .checkPointCopy .redo .xlogid = 0 ;
707
- ControlFile .checkPointCopy .redo .xrecoff = SizeOfXLogPHD ;
716
+ newXlogId = ControlFile .logId ;
717
+ newXlogSeg = ControlFile .logSeg ;
718
+ /* be sure we wrap around correctly at end of a logfile */
719
+ NextLogSeg (newXlogId , newXlogSeg );
720
+
721
+ ControlFile .checkPointCopy .redo .xlogid = newXlogId ;
722
+ ControlFile .checkPointCopy .redo .xrecoff =
723
+ newXlogSeg * XLogSegSize + SizeOfXLogPHD ;
708
724
ControlFile .checkPointCopy .undo = ControlFile .checkPointCopy .redo ;
709
725
ControlFile .checkPointCopy .time = time (NULL );
710
726
711
727
ControlFile .state = DB_SHUTDOWNED ;
712
728
ControlFile .time = time (NULL );
713
- ControlFile .logId = 0 ;
714
- ControlFile .logSeg = 1 ;
729
+ ControlFile .logId = newXlogId ;
730
+ ControlFile .logSeg = newXlogSeg + 1 ;
715
731
ControlFile .checkPoint = ControlFile .checkPointCopy .redo ;
716
732
ControlFile .prevCheckPoint .xlogid = 0 ;
717
733
ControlFile .prevCheckPoint .xrecoff = 0 ;
@@ -848,7 +864,7 @@ WriteEmptyXLOG(void)
848
864
record -> xl_crc = crc ;
849
865
850
866
/* Write the first page */
851
- XLogFileName (path , 0 , 0 );
867
+ XLogFileName (path , newXlogId , newXlogSeg );
852
868
853
869
unlink (path );
854
870
0 commit comments