Re: [HACKERS] pg_upgrade - Mailing list pgsql-patches
From | Bruce Momjian |
---|---|
Subject | Re: [HACKERS] pg_upgrade |
Date | |
Msg-id | 200201101808.g0AI80h29105@candle.pha.pa.us Whole thread Raw |
In response to | Re: [HACKERS] pg_upgrade (Tom Lane <tgl@sss.pgh.pa.us>) |
List | pgsql-patches |
Tom Lane wrote: > Bruce Momjian <pgman@candle.pha.pa.us> writes: > > Here is a patch I need to /contrib/pg_resetxlog to support a new "-x > > XID" option to set the XID in pg_control. > > I don't like this patch. It seems weird to add -x as an independent > function rather than just have pg_resetxlog do its normal thing and > allow -x to override the xid value. -x defined that way makes sense > in the context of pg_resetxlog's original mission (in particular, one > should be able to use it in the situation where the old pg_control is > unrecoverable). Also, there's no good reason for pg_upgrade not to > reset the xlog --- certainly we would not want the records therein to > be replayed against the pg_upgraded database! OK, if we want to reset WAL at the same time, which does make sense as you say, here is the patch. This is even easier for me. It just optionally sets the XID as part of the normal operation. (I am going to commit this patch because it is better for you and smaller than the one I just committed from last night.) > There is a more serious problem, also. Pages transferred over from the > old database will contain LSN values pointing into the old xlog. If > these are past the end of the new database's xlog (very probable) then > you have a strong risk of "XLogFlush: request past end of xlog" errors, > which per Vadim's insistence we treat as a system-wide fatal condition. > > Probably the cleanest way to deal with that is to tweak pg_resetxlog > further to have an optional switch with a minimum xlog position. > It already knows how to set up its cleared xlog with a position >= > end of the removed log, so you could have an additional option switch > that forces the new position to be >= switch value. To issue the > switch, pg_upgrade would have to look at the old xlog files to determine > the endpoint of the old xlog. Seems messy but not impossible. Wow, that sounds hard. Can you give me some hints which pg_control field that is in? -- Bruce Momjian | http://candle.pha.pa.us pgman@candle.pha.pa.us | (610) 853-3000 + If your life is a hard drive, | 830 Blythe Avenue + Christ can be your backup. | Drexel Hill, Pennsylvania 19026 Index: pg_resetxlog.c =================================================================== RCS file: /cvsroot/pgsql/contrib/pg_resetxlog/pg_resetxlog.c,v retrieving revision 1.10 diff -c -r1.10 pg_resetxlog.c *** pg_resetxlog.c 2001/11/05 17:46:23 1.10 --- pg_resetxlog.c 2002/01/10 18:01:51 *************** *** 23,29 **** * Portions Copyright (c) 1996-2001, PostgreSQL Global Development Group * Portions Copyright (c) 1994, Regents of the University of California * ! * $Header: /cvsroot/pgsql/contrib/pg_resetxlog/pg_resetxlog.c,v 1.10 2001/11/05 17:46:23 momjian Exp $ * *------------------------------------------------------------------------- */ --- 23,29 ---- * Portions Copyright (c) 1996-2001, PostgreSQL Global Development Group * Portions Copyright (c) 1994, Regents of the University of California * ! * $Header: /cvsroot/pgsql/contrib/pg_resetxlog/pg_resetxlog.c,v 1.11 2002/01/10 17:51:52 momjian Exp $ * *------------------------------------------------------------------------- */ *************** *** 709,715 **** * Write out the new pg_control file. */ static void ! RewriteControlFile(void) { int fd; char buffer[BLCKSZ]; /* need not be aligned */ --- 709,715 ---- * Write out the new pg_control file. */ static void ! RewriteControlFile(TransactionId set_xid) { int fd; char buffer[BLCKSZ]; /* need not be aligned */ *************** *** 737,742 **** --- 737,745 ---- ControlFile.prevCheckPoint.xlogid = 0; ControlFile.prevCheckPoint.xrecoff = 0; + if (set_xid != 0) + ControlFile.checkPointCopy.nextXid = set_xid; + /* Contents are protected with a CRC */ INIT_CRC64(ControlFile.crc); COMP_CRC64(ControlFile.crc, *************** *** 926,934 **** static void usage(void) { ! fprintf(stderr, "Usage: pg_resetxlog [-f] [-n] PGDataDirectory\n\n" ! " -f\tforce update to be done\n" ! " -n\tno update, just show extracted pg_control values (for testing)\n"); exit(1); } --- 929,938 ---- static void usage(void) { ! fprintf(stderr, "Usage: pg_resetxlog [-f] [-n] [-x xid] PGDataDirectory\n" ! " -f\tforce update to be done\n" ! " -n\tno update, just show extracted pg_control values (for testing)\n" ! " -x XID\tset XID in pg_control\n"); exit(1); } *************** *** 939,944 **** --- 943,949 ---- int argn; bool force = false; bool noupdate = false; + TransactionId set_xid = 0; int fd; char path[MAXPGPATH]; *************** *** 950,955 **** --- 955,972 ---- force = true; else if (strcmp(argv[argn], "-n") == 0) noupdate = true; + else if (strcmp(argv[argn], "-x") == 0) + { + argn++; + if (argn == argc) + usage(); + set_xid = strtoul(argv[argn], NULL, 0); + if (set_xid == 0) + { + fprintf(stderr, "XID can not be 0."); + exit(1); + } + } else usage(); } *************** *** 1018,1024 **** /* * Else, do the dirty deed. */ ! RewriteControlFile(); KillExistingXLOG(); WriteEmptyXLOG(); --- 1035,1041 ---- /* * Else, do the dirty deed. */ ! RewriteControlFile(set_xid); KillExistingXLOG(); WriteEmptyXLOG();
pgsql-patches by date: