Обсуждение: pgsql: Allow pg_resetxlog -f to reset pg_control counters using xlog

Поиск
Список
Период
Сортировка

pgsql: Allow pg_resetxlog -f to reset pg_control counters using xlog

От
momjian@postgresql.org (Bruce Momjian)
Дата:
Log Message:
-----------
Allow pg_resetxlog -f to reset pg_control counters using xlog
information, and add a -r option to reset pg_control without affecting
xlog.

yuanjia lee

Modified Files:
--------------
    pgsql/doc/src/sgml/ref:
        pg_resetxlog.sgml (r1.13 -> r1.14)
        (http://developer.postgresql.org/cvsweb.cgi/pgsql/doc/src/sgml/ref/pg_resetxlog.sgml.diff?r1=1.13&r2=1.14)
    pgsql/src/bin/pg_resetxlog:
        pg_resetxlog.c (r1.43 -> r1.44)
        (http://developer.postgresql.org/cvsweb.cgi/pgsql/src/bin/pg_resetxlog/pg_resetxlog.c.diff?r1=1.43&r2=1.44)

Re: pgsql: Allow pg_resetxlog -f to reset pg_control

От
Simon Riggs
Дата:
It appears to me that a line like this has been missed out for when
mode==GUESS

    ControlFile.checkPointCopy.ThisTimeLineID = 2;

(search for 514...)

The old line which guessed at
    ControlFile.checkPointCopy.ThisTimeLineID = 1;
has been removed, but with nothing to replace it, except in WAL mode.

I'd prefer to guess the TLI as 2, since that is usually one more than
where we got to previously, and much more likely to be a reasonable
value choice.

On Tue, 2006-04-25 at 23:17 -0300, Bruce Momjian wrote:
> Log Message:
> -----------
> Allow pg_resetxlog -f to reset pg_control counters using xlog
> information, and add a -r option to reset pg_control without affecting
> xlog.

>     pgsql/src/bin/pg_resetxlog:
>         pg_resetxlog.c (r1.43 -> r1.44)
>         (http://developer.postgresql.org/cvsweb.cgi/pgsql/src/bin/pg_resetxlog/pg_resetxlog.c.diff?r1=1.43&r2=1.44)
>

--
  Simon Riggs
  EnterpriseDB          http://www.enterprisedb.com/


Re: pgsql: Allow pg_resetxlog -f to reset pg_control

От
Bruce Momjian
Дата:
Simon Riggs wrote:
>
> It appears to me that a line like this has been missed out for when
> mode==GUESS
>
>     ControlFile.checkPointCopy.ThisTimeLineID = 2;
>
> (search for 514...)
>
> The old line which guessed at
>     ControlFile.checkPointCopy.ThisTimeLineID = 1;
> has been removed, but with nothing to replace it, except in WAL mode.
>
> I'd prefer to guess the TLI as 2, since that is usually one more than
> where we got to previously, and much more likely to be a reasonable
> value choice.

Good analysis.  I cleaned up that section and added the line you
suggested.

--
  Bruce Momjian   http://candle.pha.pa.us
  EnterpriseDB    http://www.enterprisedb.com

  + If your life is a hard drive, Christ can be your backup. +
Index: src/bin/pg_resetxlog/pg_resetxlog.c
===================================================================
RCS file: /cvsroot/pgsql/src/bin/pg_resetxlog/pg_resetxlog.c,v
retrieving revision 1.44
diff -c -c -r1.44 pg_resetxlog.c
*** src/bin/pg_resetxlog/pg_resetxlog.c    26 Apr 2006 02:17:15 -0000    1.44
--- src/bin/pg_resetxlog/pg_resetxlog.c    26 Apr 2006 18:55:03 -0000
***************
*** 565,571 ****
  {
      struct timeval tv;
      char       *localeptr;
!     bool    successed=true;

      /*
       * Set up a completely default set of pg_control values.
--- 565,571 ----
  {
      struct timeval tv;
      char       *localeptr;
!     bool    successed = true;

      /*
       * Set up a completely default set of pg_control values.
***************
*** 579,605 ****
       * update the checkpoint value in control file,by searching
       * xlog segment file, or just guessing it.
       */
!      if (mode == WAL)
!      {
          int result = SearchLastCheckpoint();
!         if ( result > 0 ) /* The last checkpoint had been found. */
          {
              ControlFile.checkPointCopy = lastcheckpoint;
              ControlFile.checkPoint = lastchkp;
              ControlFile.prevCheckPoint = prevchkp;
              ControlFile.logId = LastXLogFile->logid;
              ControlFile.logSeg = LastXLogFile->seg + 1;
-             ControlFile.checkPointCopy.ThisTimeLineID = LastXLogFile->tli;
              ControlFile.state = state;
!         } else     successed = false;

          /* Clean up the list. */
          CleanUpList(xlogfilelist);
!
!      }
!
!     if (mode == GUESS)
      {
          ControlFile.checkPointCopy.redo.xlogid = 0;
          ControlFile.checkPointCopy.redo.xrecoff = SizeOfXLogLongPHD;
          ControlFile.checkPointCopy.undo = ControlFile.checkPointCopy.redo;
--- 579,608 ----
       * update the checkpoint value in control file,by searching
       * xlog segment file, or just guessing it.
       */
!     if (mode == WAL)
!     {
          int result = SearchLastCheckpoint();
!
!         if (result > 0) /* The last checkpoint had been found. */
          {
              ControlFile.checkPointCopy = lastcheckpoint;
+             ControlFile.checkPointCopy.ThisTimeLineID = LastXLogFile->tli;
              ControlFile.checkPoint = lastchkp;
              ControlFile.prevCheckPoint = prevchkp;
+
              ControlFile.logId = LastXLogFile->logid;
              ControlFile.logSeg = LastXLogFile->seg + 1;
              ControlFile.state = state;
!         }
!         else
!             successed = false;

          /* Clean up the list. */
          CleanUpList(xlogfilelist);
!     }
!     else    /* GUESS */
      {
+         ControlFile.checkPointCopy.ThisTimeLineID = 2;
          ControlFile.checkPointCopy.redo.xlogid = 0;
          ControlFile.checkPointCopy.redo.xrecoff = SizeOfXLogLongPHD;
          ControlFile.checkPointCopy.undo = ControlFile.checkPointCopy.redo;
***************
*** 609,614 ****
--- 612,618 ----
          ControlFile.checkPointCopy.nextMultiOffset = 0;
          ControlFile.checkPointCopy.time = time(NULL);
          ControlFile.checkPoint = ControlFile.checkPointCopy.redo;
+
          /*
           * Create a new unique installation identifier, since we can no longer
           * use any old XLOG records.  See notes in xlog.c about the algorithm.
***************
*** 644,649 ****
--- 648,654 ----
          exit(1);
      }
      StrNCpy(ControlFile.lc_collate, localeptr, LOCALE_NAME_BUFLEN);
+
      localeptr = setlocale(LC_CTYPE, "");
      if (!localeptr)
      {