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

Commitf9b50b7

Browse files
committed
Fix removal of files in pgstats directories
Instead of deleting all files in stats_temp_directory and the permanentdirectory on a crash, only remove those files that match the pattern offiles we actually write in them, to avoid possibly clobbering existingunrelated contents of the temporary directory. Per complaint from JeffJanes, and subsequent discussion, starting at messageCAMkU=1z9+7RsDODnT4=cDFBRBp8wYQbd_qsLcMtKEf-oFwuOdQ@mail.gmail.comAlso, fix a bug in the same routine to avoid removing files from thepermanent directory twice (instead of once from that directory and thenfrom the temporary directory), also per report from Jeff Janes, inmessageCAMkU=1wbk947=-pAosDMX5VC+sQw9W4ttq6RM9rXu=MjNeEQKA@mail.gmail.com
1 parent3619a20 commitf9b50b7

File tree

1 file changed

+28
-5
lines changed

1 file changed

+28
-5
lines changed

‎src/backend/postmaster/pgstat.c

Lines changed: 28 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -563,15 +563,37 @@ pgstat_reset_remove_files(const char *directory)
563563
structdirent*entry;
564564
charfname[MAXPGPATH];
565565

566-
dir=AllocateDir(pgstat_stat_directory);
567-
while ((entry=ReadDir(dir,pgstat_stat_directory))!=NULL)
566+
dir=AllocateDir(directory);
567+
while ((entry=ReadDir(dir,directory))!=NULL)
568568
{
569-
if (strcmp(entry->d_name,".")==0||strcmp(entry->d_name,"..")==0)
569+
intnitems;
570+
Oidtmp_oid;
571+
chartmp_type[8];
572+
chartmp_rest[2];
573+
574+
if (strncmp(entry->d_name,".",2)==0||
575+
strncmp(entry->d_name,"..",3)==0)
570576
continue;
571577

572-
/* XXX should we try to ignore files other than the ones we write? */
578+
/*
579+
* Skip directory entries that don't match the file names we write.
580+
* See get_dbstat_filename for the database-specific pattern.
581+
*/
582+
nitems=sscanf(entry->d_name,"db_%u.%5s%1s",
583+
&tmp_oid,tmp_type,tmp_rest);
584+
if (nitems!=2)
585+
{
586+
nitems=sscanf(entry->d_name,"global.%5s%1s",
587+
tmp_type,tmp_rest);
588+
if (nitems!=1)
589+
continue;
590+
}
591+
592+
if (strncmp(tmp_type,"tmp",4)!=0&&
593+
strncmp(tmp_type,"stat",5)!=0)
594+
continue;
573595

574-
snprintf(fname,MAXPGPATH,"%s/%s",pgstat_stat_directory,
596+
snprintf(fname,MAXPGPATH,"%s/%s",directory,
575597
entry->d_name);
576598
unlink(fname);
577599
}
@@ -3631,6 +3653,7 @@ get_dbstat_filename(bool permanent, bool tempname, Oid databaseid,
36313653
{
36323654
intprinted;
36333655

3656+
/* NB -- pgstat_reset_remove_files knows about the pattern this uses */
36343657
printed=snprintf(filename,len,"%s/db_%u.%s",
36353658
permanent ?PGSTAT_STAT_PERMANENT_DIRECTORY :
36363659
pgstat_stat_directory,

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp