Re: [HACKERS] pg_resetxlog bug?

2009-05-03 Thread Tom Lane
Fujii Masao masao.fu...@gmail.com writes:
 Current pg_resetxlog doesn't remove any archive status files. This
 may cause continuous failure of archive command since .ready file
 remains even if a corresponding XLOG segment is removed. And,
 .done file without XLOG segment cannot be removed by checkpoint,
 and would remain forever. These are undesirable behaviors.

 I think that pg_resetxlog should remove existing archive status files
 of XLOG segments. Here is the patch to do so.

Applied with a trivial fix (the ending value of path isn't necessarily
right for a complaint about directory read failure, so use a constant
instead).

I back-patched as far as 8.1.  The issue exists in 8.0 too, but the
patch didn't apply immediately to 8.0 because of the above issue.
Given the lack of field complaints and 8.0's rather legacy status,
it didn't seem worth expending extra effort on.

regards, tom lane

-- 
Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-hackers


[HACKERS] pg_resetxlog bug?

2009-04-30 Thread Fujii Masao
Hi,

Current pg_resetxlog doesn't remove any archive status files. This
may cause continuous failure of archive command since .ready file
remains even if a corresponding XLOG segment is removed. And,
.done file without XLOG segment cannot be removed by checkpoint,
and would remain forever. These are undesirable behaviors.

I think that pg_resetxlog should remove existing archive status files
of XLOG segments. Here is the patch to do so.

Thought?

Regards,

-- 
Fujii Masao
NIPPON TELEGRAPH AND TELEPHONE CORPORATION
NTT Open Source Software Center
Index: src/bin/pg_resetxlog/pg_resetxlog.c
===
RCS file: /projects/cvsroot/pgsql/src/bin/pg_resetxlog/pg_resetxlog.c,v
retrieving revision 1.72
diff -c -r1.72 pg_resetxlog.c
*** src/bin/pg_resetxlog/pg_resetxlog.c	25 Feb 2009 13:03:07 -	1.72
--- src/bin/pg_resetxlog/pg_resetxlog.c	30 Apr 2009 14:42:48 -
***
*** 71,76 
--- 71,77 
  static void RewriteControlFile(void);
  static void FindEndOfXLOG(void);
  static void KillExistingXLOG(void);
+ static void KillExistingArchiveStatus(void);
  static void WriteEmptyXLOG(void);
  static void usage(void);
  
***
*** 360,365 
--- 361,367 
  	 */
  	RewriteControlFile();
  	KillExistingXLOG();
+ 	KillExistingArchiveStatus();
  	WriteEmptyXLOG();
  
  	printf(_(Transaction log reset\n));
***
*** 812,817 
--- 814,875 
  
  
  /*
+  * Remove existing archive status files
+  */
+ static void
+ KillExistingArchiveStatus(void)
+ {
+ 	DIR		   *xldir;
+ 	struct dirent *xlde;
+ 	char		path[MAXPGPATH];
+ 
+ 	snprintf(path, MAXPGPATH, XLOGDIR /archive_status);
+ 	xldir = opendir(path);
+ 	if (xldir == NULL)
+ 	{
+ 		fprintf(stderr, _(%s: could not open directory \%s\: %s\n),
+ progname, path, strerror(errno));
+ 		exit(1);
+ 	}
+ 
+ 	errno = 0;
+ 	while ((xlde = readdir(xldir)) != NULL)
+ 	{
+ 		if (strspn(xlde-d_name, 0123456789ABCDEF) == 24 
+ 			(strcmp(xlde-d_name + 24, .ready) == 0 ||
+ 			 strcmp(xlde-d_name + 24, .done)  == 0))
+ 		{
+ 			snprintf(path, MAXPGPATH, XLOGDIR /archive_status/%s, xlde-d_name);
+ 			if (unlink(path)  0)
+ 			{
+ fprintf(stderr, _(%s: could not delete file \%s\: %s\n),
+ 		progname, path, strerror(errno));
+ exit(1);
+ 			}
+ 		}
+ 		errno = 0;
+ 	}
+ #ifdef WIN32
+ 
+ 	/*
+ 	 * This fix is in mingw cvs (runtime/mingwex/dirent.c rev 1.4), but not in
+ 	 * released version
+ 	 */
+ 	if (GetLastError() == ERROR_NO_MORE_FILES)
+ 		errno = 0;
+ #endif
+ 
+ 	if (errno)
+ 	{
+ 		fprintf(stderr, _(%s: could not read from directory \%s\: %s\n),
+ progname, path, strerror(errno));
+ 		exit(1);
+ 	}
+ 	closedir(xldir);
+ }
+ 
+ 
+ /*
   * Write an empty XLOG file, containing only the checkpoint record
   * already set up in ControlFile.
   */

-- 
Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-hackers


Re: [HACKERS] pg_resetxlog bug?

2009-04-30 Thread Simon Riggs

On Fri, 2009-05-01 at 00:07 +0900, Fujii Masao wrote:

 Current pg_resetxlog doesn't remove any archive status files. This
 may cause continuous failure of archive command since .ready file
 remains even if a corresponding XLOG segment is removed. And,
 .done file without XLOG segment cannot be removed by checkpoint,
 and would remain forever. These are undesirable behaviors.

Agreed

 I think that pg_resetxlog should remove existing archive status files
 of XLOG segments. Here is the patch to do so.

Seems OK.

-- 
 Simon Riggs   www.2ndQuadrant.com
 PostgreSQL Training, Services and Support


-- 
Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-hackers