Hi,

I'd like to propose to change pg_controldata so that it reports the name
of WAL file containing the latest checkpoint's REDO record, as follows:

    $ pg_controldata $PGDATA
    ...
    Latest checkpoint's REDO location:    0/16D6ACC (file
000000010000000000000001)
    Latest checkpoint's TimeLineID:       1
    ...

This simplifies very much the way to calculate the archive file cutoff point
because the reported WAL file is just cutoff point itself. If the file name is
not reported, we have to calculate the cutoff point from the reported
location and timeline, which is complicated calculation. We can use
pg_xlogfile_name function to calculate that, but it cannot be executed in
the standby. Another problem is that pg_xlogfile_name always uses
current timeline for the calculation, so if the reported timeline is not
the same as current one, pg_xlogfile_name cannot return the correct WAL
file name. Making pg_controldata report that WAL file name gets rid of
such a complexity.

You may think that archive_cleanup_command is usable for that purpose.
That's true. But it's not usable simply for  the case where there are more
than one standby servers. In this case, the archive file cutoff point needs
to be calculated from each standby's REDO location and timeline.

Attached patch changes pg_controldata as above. Thought?

Regards,

-- 
Fujii Masao
NIPPON TELEGRAPH AND TELEPHONE CORPORATION
NTT Open Source Software Center
*** a/src/bin/pg_controldata/pg_controldata.c
--- b/src/bin/pg_controldata/pg_controldata.c
***************
*** 24,29 ****
--- 24,30 ----
  #include <fcntl.h>
  
  #include "access/xlog.h"
+ #include "access/xlog_internal.h"
  #include "catalog/pg_control.h"
  
  
***************
*** 101,106 **** main(int argc, char *argv[])
--- 102,110 ----
  	char		sysident_str[32];
  	const char *strftime_fmt = "%c";
  	const char *progname;
+ 	uint32	log;
+ 	uint32	seg;
+ 	char		xlogfilename[MAXFNAMELEN];
  
  	set_pglocale_pgservice(argv[0], PG_TEXTDOMAIN("pg_controldata"));
  
***************
*** 177,182 **** main(int argc, char *argv[])
--- 181,193 ----
  			 localtime(&time_tmp));
  
  	/*
+ 	 * Calculate the WAL file name containing the latest checkpoint's REDO
+ 	 * record.
+ 	 */
+ 	XLByteToSeg(ControlFile.checkPointCopy.redo, log, seg);
+ 	XLogFileName(xlogfilename, ControlFile.checkPointCopy.ThisTimeLineID, log, seg);
+ 
+ 	/*
  	 * Format system_identifier separately to keep platform-dependent format
  	 * code out of the translatable message string.
  	 */
***************
*** 204,212 **** main(int argc, char *argv[])
  	printf(_("Prior checkpoint location:            %X/%X\n"),
  		   ControlFile.prevCheckPoint.xlogid,
  		   ControlFile.prevCheckPoint.xrecoff);
! 	printf(_("Latest checkpoint's REDO location:    %X/%X\n"),
  		   ControlFile.checkPointCopy.redo.xlogid,
! 		   ControlFile.checkPointCopy.redo.xrecoff);
  	printf(_("Latest checkpoint's TimeLineID:       %u\n"),
  		   ControlFile.checkPointCopy.ThisTimeLineID);
  	printf(_("Latest checkpoint's full_page_writes: %s\n"),
--- 215,224 ----
  	printf(_("Prior checkpoint location:            %X/%X\n"),
  		   ControlFile.prevCheckPoint.xlogid,
  		   ControlFile.prevCheckPoint.xrecoff);
! 	printf(_("Latest checkpoint's REDO location:    %X/%X (file %s)\n"),
  		   ControlFile.checkPointCopy.redo.xlogid,
! 		   ControlFile.checkPointCopy.redo.xrecoff,
! 		   xlogfilename);
  	printf(_("Latest checkpoint's TimeLineID:       %u\n"),
  		   ControlFile.checkPointCopy.ThisTimeLineID);
  	printf(_("Latest checkpoint's full_page_writes: %s\n"),
-- 
Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-hackers

Reply via email to