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.16 2002/01/11 06:33:01 momjian Exp $
26
+ * $Header: /cvsroot/pgsql/contrib/pg_resetxlog/Attic/pg_resetxlog.c,v 1.17 2002/01/11 21:27:13 tgl Exp $
27
27
*
28
28
*-------------------------------------------------------------------------
29
29
*/
63
63
snprintf(path, MAXPGPATH, "%s/%08X%08X", \
64
64
XLogDir, log, seg)
65
65
66
-
67
66
/******************** end of stuff copied from xlog.c ********************/
68
67
69
68
@@ -134,7 +133,7 @@ ReadControlFile(void)
134
133
return true;
135
134
}
136
135
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" );
138
137
/* We will use the data anyway, but treat it as guessed. */
139
138
memcpy (& ControlFile , buffer , sizeof (ControlFile ));
140
139
guessed = true;
@@ -218,12 +217,11 @@ GuessControlValues(void)
218
217
static void
219
218
PrintControlValues (bool guessed )
220
219
{
221
- printf ("\n %spg_control values:\n\n"
220
+ printf ("%spg_control values:\n\n"
222
221
"pg_control version number: %u\n"
223
222
"Catalog version number: %u\n"
224
223
"Current log file id: %u\n"
225
224
"Next log file segment: %u\n"
226
- "Latest checkpoint location: %X/%X\n"
227
225
"Latest checkpoint's StartUpID: %u\n"
228
226
"Latest checkpoint's NextXID: %u\n"
229
227
"Latest checkpoint's NextOID: %u\n"
@@ -237,8 +235,6 @@ PrintControlValues(bool guessed)
237
235
ControlFile .catalog_version_no ,
238
236
ControlFile .logId ,
239
237
ControlFile .logSeg ,
240
- ControlFile .checkPoint .xlogid ,
241
- ControlFile .checkPoint .xrecoff ,
242
238
ControlFile .checkPointCopy .ThisStartUpID ,
243
239
ControlFile .checkPointCopy .nextXid ,
244
240
ControlFile .checkPointCopy .nextOid ,
@@ -253,7 +249,7 @@ PrintControlValues(bool guessed)
253
249
* Write out the new pg_control file.
254
250
*/
255
251
static void
256
- RewriteControlFile (TransactionId set_xid , XLogRecPtr set_checkpoint )
252
+ RewriteControlFile (void )
257
253
{
258
254
int fd ;
259
255
char buffer [BLCKSZ ]; /* need not be aligned */
@@ -277,18 +273,10 @@ RewriteControlFile(TransactionId set_xid, XLogRecPtr set_checkpoint)
277
273
ControlFile .time = time (NULL );
278
274
ControlFile .logId = newXlogId ;
279
275
ControlFile .logSeg = newXlogSeg + 1 ;
276
+ ControlFile .checkPoint = ControlFile .checkPointCopy .redo ;
280
277
ControlFile .prevCheckPoint .xlogid = 0 ;
281
278
ControlFile .prevCheckPoint .xrecoff = 0 ;
282
279
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
-
292
280
/* Contents are protected with a CRC */
293
281
INIT_CRC64 (ControlFile .crc );
294
282
COMP_CRC64 (ControlFile .crc ,
@@ -478,11 +466,11 @@ WriteEmptyXLOG(void)
478
466
static void
479
467
usage (void )
480
468
{
481
- fprintf (stderr , "Usage: pg_resetxlog [-f] [-n] [-x xid] [ -l log_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
- " -x XID set XID in pg_control \n"
485
- " -l log_id offset set hex checkpoint location in pg_control \n" );
469
+ fprintf (stderr , "Usage: pg_resetxlog [-f] [-n] [-x xid] [ -l fileid 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
+ " -x xid\tset next transaction ID \n"
473
+ " -l fileid seg\tforce minimum WAL starting location for new xlog \n" );
486
474
exit (1 );
487
475
}
488
476
@@ -494,7 +482,8 @@ main(int argc, char **argv)
494
482
bool force = false;
495
483
bool noupdate = false;
496
484
TransactionId set_xid = 0 ;
497
- XLogRecPtr set_checkpoint = {0 ,0 };
485
+ uint32 minXlogId = 0 ,
486
+ minXlogSeg = 0 ;
498
487
int fd ;
499
488
char path [MAXPGPATH ];
500
489
@@ -514,7 +503,7 @@ main(int argc, char **argv)
514
503
set_xid = strtoul (argv [argn ], NULL , 0 );
515
504
if (set_xid == 0 )
516
505
{
517
- fprintf (stderr , "XID can not be 0." );
506
+ fprintf (stderr , "XID can not be 0.\n " );
518
507
exit (1 );
519
508
}
520
509
}
@@ -523,17 +512,11 @@ main(int argc, char **argv)
523
512
argn ++ ;
524
513
if (argn == argc )
525
514
usage ();
526
- set_checkpoint . xlogid = strtoul (argv [argn ], NULL , 16 );
515
+ minXlogId = strtoul (argv [argn ], NULL , 0 );
527
516
argn ++ ;
528
517
if (argn == argc )
529
518
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 );
537
520
}
538
521
else
539
522
usage ();
@@ -606,8 +589,20 @@ main(int argc, char **argv)
606
589
607
590
/*
608
591
* Else, do the dirty deed.
592
+ *
593
+ * First adjust fields if required by switches.
609
594
*/
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 ();
611
606
KillExistingXLOG ();
612
607
WriteEmptyXLOG ();
613
608
0 commit comments