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

Commitdb5b49c

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 parent38c6923 commitdb5b49c

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
@@ -562,15 +562,37 @@ pgstat_reset_remove_files(const char *directory)
562562
structdirent*entry;
563563
charfname[MAXPGPATH];
564564

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

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

573-
snprintf(fname,MAXPGPATH,"%s/%s",pgstat_stat_directory,
595+
snprintf(fname,MAXPGPATH,"%s/%s",directory,
574596
entry->d_name);
575597
unlink(fname);
576598
}
@@ -3627,6 +3649,7 @@ get_dbstat_filename(bool permanent, bool tempname, Oid databaseid,
36273649
{
36283650
intprinted;
36293651

3652+
/* NB -- pgstat_reset_remove_files knows about the pattern this uses */
36303653
printed=snprintf(filename,len,"%s/db_%u.%s",
36313654
permanent ?PGSTAT_STAT_PERMANENT_DIRECTORY :
36323655
pgstat_stat_directory,

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp