mirror of
https://github.com/postgres/postgres.git
synced 2025-04-29 13:56:47 +03:00
Fix pg_resetxlog to remove archive status files along with WAL segment files.
Fujii Masao
This commit is contained in:
parent
f8d10e50d3
commit
5379bf74d7
@ -23,7 +23,7 @@
|
|||||||
* Portions Copyright (c) 1996-2005, PostgreSQL Global Development Group
|
* Portions Copyright (c) 1996-2005, PostgreSQL Global Development Group
|
||||||
* Portions Copyright (c) 1994, Regents of the University of California
|
* Portions Copyright (c) 1994, Regents of the University of California
|
||||||
*
|
*
|
||||||
* $PostgreSQL: pgsql/src/bin/pg_resetxlog/pg_resetxlog.c,v 1.38 2005/10/15 02:49:40 momjian Exp $
|
* $PostgreSQL: pgsql/src/bin/pg_resetxlog/pg_resetxlog.c,v 1.38.2.1 2009/05/03 23:13:56 tgl Exp $
|
||||||
*
|
*
|
||||||
*-------------------------------------------------------------------------
|
*-------------------------------------------------------------------------
|
||||||
*/
|
*/
|
||||||
@ -61,6 +61,7 @@ static void GuessControlValues(void);
|
|||||||
static void PrintControlValues(bool guessed);
|
static void PrintControlValues(bool guessed);
|
||||||
static void RewriteControlFile(void);
|
static void RewriteControlFile(void);
|
||||||
static void KillExistingXLOG(void);
|
static void KillExistingXLOG(void);
|
||||||
|
static void KillExistingArchiveStatus(void);
|
||||||
static void WriteEmptyXLOG(void);
|
static void WriteEmptyXLOG(void);
|
||||||
static void usage(void);
|
static void usage(void);
|
||||||
|
|
||||||
@ -328,6 +329,7 @@ main(int argc, char *argv[])
|
|||||||
*/
|
*/
|
||||||
RewriteControlFile();
|
RewriteControlFile();
|
||||||
KillExistingXLOG();
|
KillExistingXLOG();
|
||||||
|
KillExistingArchiveStatus();
|
||||||
WriteEmptyXLOG();
|
WriteEmptyXLOG();
|
||||||
|
|
||||||
printf(_("Transaction log reset\n"));
|
printf(_("Transaction log reset\n"));
|
||||||
@ -690,6 +692,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
|
* Write an empty XLOG file, containing only the checkpoint record
|
||||||
* already set up in ControlFile.
|
* already set up in ControlFile.
|
||||||
|
Loading…
x
Reference in New Issue
Block a user