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 -0000 1.72
--- src/bin/pg_resetxlog/pg_resetxlog.c 30 Apr 2009 14:42:48 -0000
***************
*** 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 ([email protected])
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-hackers