Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commitd85c688

Browse files
committed
Fix pg_resetxlog to remove archive status files along with WAL segment files.
Fujii Masao
1 parentc52963a commitd85c688

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/2513: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
staticvoidRewriteControlFile(void);
7272
staticvoidFindEndOfXLOG(void);
7373
staticvoidKillExistingXLOG(void);
74+
staticvoidKillExistingArchiveStatus(void);
7475
staticvoidWriteEmptyXLOG(void);
7576
staticvoidusage(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+
staticvoid
820+
KillExistingArchiveStatus(void)
821+
{
822+
DIR*xldir;
823+
structdirent*xlde;
824+
charpath[MAXPGPATH];
825+
826+
#defineARCHSTATDIRXLOGDIR "/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+
#ifdefWIN32
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)

[8]ページ先頭

©2009-2025 Movatter.jp