summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTom Lane2009-05-03 23:13:37 +0000
committerTom Lane2009-05-03 23:13:37 +0000
commitbcaef8b5a0e2d5c143dabd8516090a09e39b27b8 (patch)
treeede5cdcb78e8b2491ab7e4168f366d3debe09374
parent5fbf6fbc36e9988e1e3e98273843f26fd9d6d4bb (diff)
Fix pg_resetxlog to remove archive status files along with WAL segment files.
Fujii Masao
-rw-r--r--src/bin/pg_resetxlog/pg_resetxlog.c59
1 files changed, 59 insertions, 0 deletions
diff --git a/src/bin/pg_resetxlog/pg_resetxlog.c b/src/bin/pg_resetxlog/pg_resetxlog.c
index 0d3c42693e..62a2fd6150 100644
--- a/src/bin/pg_resetxlog/pg_resetxlog.c
+++ b/src/bin/pg_resetxlog/pg_resetxlog.c
@@ -71,6 +71,7 @@ static void PrintControlValues(bool guessed);
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,6 +361,7 @@ main(int argc, char *argv[])
*/
RewriteControlFile();
KillExistingXLOG();
+ KillExistingArchiveStatus();
WriteEmptyXLOG();
printf(_("Transaction log reset\n"));
@@ -812,6 +814,63 @@ KillExistingXLOG(void)
/*
+ * Remove existing archive status files
+ */
+static void
+KillExistingArchiveStatus(void)
+{
+ DIR *xldir;
+ struct dirent *xlde;
+ char path[MAXPGPATH];
+
+#define ARCHSTATDIR XLOGDIR "/archive_status"
+
+ xldir = opendir(ARCHSTATDIR);
+ if (xldir == NULL)
+ {
+ fprintf(stderr, _("%s: could not open directory \"%s\": %s\n"),
+ progname, ARCHSTATDIR, 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, "%s/%s", ARCHSTATDIR, 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, ARCHSTATDIR, strerror(errno));
+ exit(1);
+ }
+ closedir(xldir);
+}
+
+
+/*
* Write an empty XLOG file, containing only the checkpoint record
* already set up in ControlFile.
*/