Re: [HACKERS] pg_upgrade - Mailing list pgsql-patches

From Bruce Momjian
Subject Re: [HACKERS] pg_upgrade
Date
Msg-id 200201101952.g0AJqDL10213@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:
> > Also, how do I find the current xlog segment position.  Is it one of
> > these fields shown by pg_controldata?
>
> "latest checkpoint location" should do.
>
> BTW, if your script is relying on pg_resetxlog to be available, best to
> ensure that it's there before you do anything irreversible ...

OK, here is code to set the checkpoint log id and offset using a new -l
flag.  It also now displays the checkpoint location with -n.

--
  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: contrib/pg_resetxlog/README.pg_resetxlog
===================================================================
RCS file: /cvsroot/pgsql/contrib/pg_resetxlog/README.pg_resetxlog,v
retrieving revision 1.2
diff -c -r1.2 README.pg_resetxlog
*** contrib/pg_resetxlog/README.pg_resetxlog    2002/01/10 17:51:52    1.2
--- contrib/pg_resetxlog/README.pg_resetxlog    2002/01/10 19:49:23
***************
*** 22,28 ****
  the database software.

  A tertiary purpose it its use by pg_upgrade to set the next transaction
! id in pg_control.

  To run the program, make sure your postmaster is not running, then
  (as the Postgres admin user) do
--- 22,28 ----
  the database software.

  A tertiary purpose it its use by pg_upgrade to set the next transaction
! id and checkpoint location in pg_control.

  To run the program, make sure your postmaster is not running, then
  (as the Postgres admin user) do
Index: contrib/pg_resetxlog/pg_resetxlog.c
===================================================================
RCS file: /cvsroot/pgsql/contrib/pg_resetxlog/pg_resetxlog.c,v
retrieving revision 1.12
diff -c -r1.12 pg_resetxlog.c
*** contrib/pg_resetxlog/pg_resetxlog.c    2002/01/10 18:08:29    1.12
--- contrib/pg_resetxlog/pg_resetxlog.c    2002/01/10 19:49:24
***************
*** 683,688 ****
--- 683,689 ----
             "Catalog version number:               %u\n"
             "Current log file id:                  %u\n"
             "Next log file segment:                %u\n"
+            "Latest checkpoint location:           %X/%X\n"
             "Latest checkpoint's StartUpID:        %u\n"
             "Latest checkpoint's NextXID:          %u\n"
             "Latest checkpoint's NextOID:          %u\n"
***************
*** 695,700 ****
--- 696,703 ----
             ControlFile.catalog_version_no,
             ControlFile.logId,
             ControlFile.logSeg,
+            ControlFile.checkPoint.xlogid,
+            ControlFile.checkPoint.xrecoff,
             ControlFile.checkPointCopy.ThisStartUpID,
             ControlFile.checkPointCopy.nextXid,
             ControlFile.checkPointCopy.nextOid,
***************
*** 709,715 ****
   * Write out the new pg_control file.
   */
  static void
! RewriteControlFile(TransactionId set_xid)
  {
      int            fd;
      char        buffer[BLCKSZ]; /* need not be aligned */
--- 712,718 ----
   * Write out the new pg_control file.
   */
  static void
! RewriteControlFile(TransactionId set_xid, XLogRecPtr set_checkpoint)
  {
      int            fd;
      char        buffer[BLCKSZ]; /* need not be aligned */
***************
*** 733,745 ****
      ControlFile.time = time(NULL);
      ControlFile.logId = newXlogId;
      ControlFile.logSeg = newXlogSeg + 1;
-     ControlFile.checkPoint = ControlFile.checkPointCopy.redo;
      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,
--- 736,753 ----
      ControlFile.time = time(NULL);
      ControlFile.logId = newXlogId;
      ControlFile.logSeg = newXlogSeg + 1;
      ControlFile.prevCheckPoint.xlogid = 0;
      ControlFile.prevCheckPoint.xrecoff = 0;

      if (set_xid != 0)
          ControlFile.checkPointCopy.nextXid = set_xid;
!
!     if (set_checkpoint.xlogid == 0 &&
!         set_checkpoint.xrecoff == 0)
!         ControlFile.checkPoint = ControlFile.checkPointCopy.redo;
!     else
!         ControlFile.checkPoint = set_checkpoint;
!
      /* Contents are protected with a CRC */
      INIT_CRC64(ControlFile.crc);
      COMP_CRC64(ControlFile.crc,
***************
*** 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);
  }

--- 937,947 ----
  static void
  usage(void)
  {
!     fprintf(stderr, "Usage: pg_resetxlog [-f] [-n] [-x xid] [ -l log_id offset ] PGDataDirectory\n"
!             "  -f\t  force update to be done\n"
!             "  -n\t  no update, just show extracted pg_control values (for testing)\n"
!             "  -x XID  set XID in pg_control\n"
!             "  -l log_id offset   set checkpoint location in pg_control\n");
      exit(1);
  }

***************
*** 944,949 ****
--- 953,959 ----
      bool        force = false;
      bool        noupdate = false;
      TransactionId set_xid = 0;
+     XLogRecPtr    set_checkpoint = {0,0};
      int            fd;
      char        path[MAXPGPATH];

***************
*** 967,972 ****
--- 977,999 ----
                  exit(1);
              }
          }
+         else if (strcmp(argv[argn], "-l") == 0)
+         {
+             argn++;
+             if (argn == argc)
+                 usage();
+             set_checkpoint.xlogid = strtoul(argv[argn], NULL, 0);
+             argn++;
+             if (argn == argc)
+                 usage();
+             set_checkpoint.xrecoff = strtoul(argv[argn], NULL, 0);
+             if (set_checkpoint.xlogid == 0 &&
+                 set_checkpoint.xrecoff == 0)
+             {
+                 fprintf(stderr, "Checkpoint can not be '0 0'.");
+                 exit(1);
+             }
+         }
          else
              usage();
      }
***************
*** 1035,1041 ****
      /*
       * Else, do the dirty deed.
       */
!     RewriteControlFile(set_xid);
      KillExistingXLOG();
      WriteEmptyXLOG();

--- 1062,1068 ----
      /*
       * Else, do the dirty deed.
       */
!     RewriteControlFile(set_xid, set_checkpoint);
      KillExistingXLOG();
      WriteEmptyXLOG();


pgsql-patches by date:

Previous
From: Bruce Momjian
Date:
Subject: Re: [HACKERS] pg_upgrade
Next
From: "Greg Sabino Mullane"
Date:
Subject: doc/src/FAQ/FAQ.html changes