Skip to content

Commit 4c0e9b5

Browse files
committed
Add new -l flag to set checkpoint location for /contrib/pg_resetxlog.
1 parent 0385ba1 commit 4c0e9b5

File tree

2 files changed

+37
-10
lines changed

2 files changed

+37
-10
lines changed

contrib/pg_resetxlog/README.pg_resetxlog

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ Then run pg_resetxlog, and finally install and start the new version of
2222
the database software.
2323

2424
A tertiary purpose it its use by pg_upgrade to set the next transaction
25-
id in pg_control.
25+
id and checkpoint location in pg_control.
2626

2727
To run the program, make sure your postmaster is not running, then
2828
(as the Postgres admin user) do

contrib/pg_resetxlog/pg_resetxlog.c

Lines changed: 36 additions & 9 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.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 $
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)
695696
ControlFile.catalog_version_no,
696697
ControlFile.logId,
697698
ControlFile.logSeg,
699+
ControlFile.checkPoint.xlogid,
700+
ControlFile.checkPoint.xrecoff,
698701
ControlFile.checkPointCopy.ThisStartUpID,
699702
ControlFile.checkPointCopy.nextXid,
700703
ControlFile.checkPointCopy.nextOid,
@@ -709,7 +712,7 @@ PrintControlValues(void)
709712
* Write out the new pg_control file.
710713
*/
711714
static void
712-
RewriteControlFile(TransactionId set_xid)
715+
RewriteControlFile(TransactionId set_xid, XLogRecPtr set_checkpoint)
713716
{
714717
int fd;
715718
char buffer[BLCKSZ]; /* need not be aligned */
@@ -733,13 +736,18 @@ RewriteControlFile(TransactionId set_xid)
733736
ControlFile.time = time(NULL);
734737
ControlFile.logId = newXlogId;
735738
ControlFile.logSeg = newXlogSeg + 1;
736-
ControlFile.checkPoint = ControlFile.checkPointCopy.redo;
737739
ControlFile.prevCheckPoint.xlogid = 0;
738740
ControlFile.prevCheckPoint.xrecoff = 0;
739741

740742
if (set_xid != 0)
741743
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+
743751
/* Contents are protected with a CRC */
744752
INIT_CRC64(ControlFile.crc);
745753
COMP_CRC64(ControlFile.crc,
@@ -929,10 +937,11 @@ WriteEmptyXLOG(void)
929937
static void
930938
usage(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");
936945
exit(1);
937946
}
938947

@@ -944,6 +953,7 @@ main(int argc, char **argv)
944953
bool force = false;
945954
bool noupdate = false;
946955
TransactionId set_xid = 0;
956+
XLogRecPtr set_checkpoint = {0,0};
947957
int fd;
948958
char path[MAXPGPATH];
949959

@@ -967,6 +977,23 @@ main(int argc, char **argv)
967977
exit(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+
}
970997
else
971998
usage();
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);
10391066
KillExistingXLOG();
10401067
WriteEmptyXLOG();
10411068

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy