Print the name of the WAL file containing latest REDO ptr in pg_controldata.
authorHeikki Linnakangas <heikki.linnakangas@iki.fi>
Sat, 14 Jul 2012 11:17:43 +0000 (14:17 +0300)
committerHeikki Linnakangas <heikki.linnakangas@iki.fi>
Sat, 14 Jul 2012 11:22:57 +0000 (14:22 +0300)
This makes it easier to determine how far back you need to keep archived WAL
files, to restore from a backup.

Fujii Masao

src/bin/pg_controldata/pg_controldata.c

index 298f836504f55445bf1231627354dce96c7af1c8..129c4d0dda3588e5444ccd9baddc14bdbe35f82e 100644 (file)
@@ -24,6 +24,7 @@
 #include <fcntl.h>
 
 #include "access/xlog.h"
+#include "access/xlog_internal.h"
 #include "catalog/pg_control.h"
 
 
@@ -95,6 +96,8 @@ main(int argc, char *argv[])
    char        sysident_str[32];
    const char *strftime_fmt = "%c";
    const char *progname;
+   XLogSegNo   segno;
+   char        xlogfilename[MAXFNAMELEN];
 
    set_pglocale_pgservice(argv[0], PG_TEXTDOMAIN("pg_controldata"));
 
@@ -170,6 +173,13 @@ main(int argc, char *argv[])
    strftime(ckpttime_str, sizeof(ckpttime_str), strftime_fmt,
             localtime(&time_tmp));
 
+   /*
+    * Calculate name of the WAL file containing the latest checkpoint's REDO
+    * start point.
+    */
+   XLByteToSeg(ControlFile.checkPointCopy.redo, segno);
+   XLogFileName(xlogfilename, ControlFile.checkPointCopy.ThisTimeLineID, segno);
+
    /*
     * Format system_identifier separately to keep platform-dependent format
     * code out of the translatable message string.
@@ -201,6 +211,8 @@ main(int argc, char *argv[])
    printf(_("Latest checkpoint's REDO location:    %X/%X\n"),
           (uint32) (ControlFile.checkPointCopy.redo >> 32),
           (uint32) ControlFile.checkPointCopy.redo);
+   printf(_("Latest checkpoint's REDO WAL file:    %s\n"),
+          xlogfilename);
    printf(_("Latest checkpoint's TimeLineID:       %u\n"),
           ControlFile.checkPointCopy.ThisTimeLineID);
    printf(_("Latest checkpoint's full_page_writes: %s\n"),