Skip to content

Commit d85c688

Browse files
committed
Fix pg_resetxlog to remove archive status files along with WAL segment files.
Fujii Masao
1 parent c52963a commit d85c688

File tree

1 file changed

+60
-1
lines changed

1 file changed

+60
-1
lines changed

src/bin/pg_resetxlog/pg_resetxlog.c

Lines changed: 60 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
* Portions Copyright (c) 1996-2009, PostgreSQL Global Development Group
2424
* Portions Copyright (c) 1994, Regents of the University of California
2525
*
26-
* $PostgreSQL: pgsql/src/bin/pg_resetxlog/pg_resetxlog.c,v 1.72 2009/02/25 13:03:07 petere Exp $
26+
* $PostgreSQL: pgsql/src/bin/pg_resetxlog/pg_resetxlog.c,v 1.73 2009/05/03 23:13:37 tgl Exp $
2727
*
2828
*-------------------------------------------------------------------------
2929
*/
@@ -71,6 +71,7 @@ static void PrintControlValues(bool guessed);
7171
static void RewriteControlFile(void);
7272
static void FindEndOfXLOG(void);
7373
static void KillExistingXLOG(void);
74+
static void KillExistingArchiveStatus(void);
7475
static void WriteEmptyXLOG(void);
7576
static void usage(void);
7677

@@ -360,6 +361,7 @@ main(int argc, char *argv[])
360361
*/
361362
RewriteControlFile();
362363
KillExistingXLOG();
364+
KillExistingArchiveStatus();
363365
WriteEmptyXLOG();
364366

365367
printf(_("Transaction log reset\n"));
@@ -811,6 +813,63 @@ KillExistingXLOG(void)
811813
}
812814

813815

816+
/*
817+
* Remove existing archive status files
818+
*/
819+
static void
820+
KillExistingArchiveStatus(void)
821+
{
822+
DIR *xldir;
823+
struct dirent *xlde;
824+
char path[MAXPGPATH];
825+
826+
#define ARCHSTATDIR XLOGDIR "/archive_status"
827+
828+
xldir = opendir(ARCHSTATDIR);
829+
if (xldir == NULL)
830+
{
831+
fprintf(stderr, _("%s: could not open directory \"%s\": %s\n"),
832+
progname, ARCHSTATDIR, strerror(errno));
833+
exit(1);
834+
}
835+
836+
errno = 0;
837+
while ((xlde = readdir(xldir)) != NULL)
838+
{
839+
if (strspn(xlde->d_name, "0123456789ABCDEF") == 24 &&
840+
(strcmp(xlde->d_name + 24, ".ready") == 0 ||
841+
strcmp(xlde->d_name + 24, ".done") == 0))
842+
{
843+
snprintf(path, MAXPGPATH, "%s/%s", ARCHSTATDIR, xlde->d_name);
844+
if (unlink(path) < 0)
845+
{
846+
fprintf(stderr, _("%s: could not delete file \"%s\": %s\n"),
847+
progname, path, strerror(errno));
848+
exit(1);
849+
}
850+
}
851+
errno = 0;
852+
}
853+
#ifdef WIN32
854+
855+
/*
856+
* This fix is in mingw cvs (runtime/mingwex/dirent.c rev 1.4), but not in
857+
* released version
858+
*/
859+
if (GetLastError() == ERROR_NO_MORE_FILES)
860+
errno = 0;
861+
#endif
862+
863+
if (errno)
864+
{
865+
fprintf(stderr, _("%s: could not read from directory \"%s\": %s\n"),
866+
progname, ARCHSTATDIR, strerror(errno));
867+
exit(1);
868+
}
869+
closedir(xldir);
870+
}
871+
872+
814873
/*
815874
* Write an empty XLOG file, containing only the checkpoint record
816875
* already set up in ControlFile.

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy