|
23 | 23 | * Portions Copyright (c) 1996-2009, PostgreSQL Global Development Group
|
24 | 24 | * Portions Copyright (c) 1994, Regents of the University of California
|
25 | 25 | *
|
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 $ |
27 | 27 | *
|
28 | 28 | *-------------------------------------------------------------------------
|
29 | 29 | */
|
@@ -71,6 +71,7 @@ static void PrintControlValues(bool guessed);
|
71 | 71 | staticvoidRewriteControlFile(void);
|
72 | 72 | staticvoidFindEndOfXLOG(void);
|
73 | 73 | staticvoidKillExistingXLOG(void);
|
| 74 | +staticvoidKillExistingArchiveStatus(void); |
74 | 75 | staticvoidWriteEmptyXLOG(void);
|
75 | 76 | staticvoidusage(void);
|
76 | 77 |
|
@@ -360,6 +361,7 @@ main(int argc, char *argv[])
|
360 | 361 | */
|
361 | 362 | RewriteControlFile();
|
362 | 363 | KillExistingXLOG();
|
| 364 | +KillExistingArchiveStatus(); |
363 | 365 | WriteEmptyXLOG();
|
364 | 366 |
|
365 | 367 | printf(_("Transaction log reset\n"));
|
@@ -811,6 +813,63 @@ KillExistingXLOG(void)
|
811 | 813 | }
|
812 | 814 |
|
813 | 815 |
|
| 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 | + |
814 | 873 | /*
|
815 | 874 | * Write an empty XLOG file, containing only the checkpoint record
|
816 | 875 | * already set up in ControlFile.
|
|