Race condition in pg_database_size() - Mailing list pgsql-hackers

From Michael Fuhr
Subject Race condition in pg_database_size()
Date
Msg-id 20070310163100.GA91660@winnie.fuhr.org
Whole thread Raw
Responses Re: Race condition in pg_database_size()
List pgsql-hackers
I'm occasionally seeing calls to pg_database_size() fail with

ERROR:  could not stat file "/var/lib/pgsql/data/base/16404/1738343": No such file or directory

So far I haven't noticed any other problems that might be related
to this error.  This database frequently uses temporary tables so
I'm wondering if the error might be due to a race condition in
db_dir_size(), which does the following:
   while ((direntry = ReadDir(dirdesc, path)) != NULL)   {       struct stat fst;
       if (strcmp(direntry->d_name, ".") == 0 ||           strcmp(direntry->d_name, "..") == 0)           continue;
       snprintf(filename, MAXPGPATH, "%s/%s", path, direntry->d_name);
       if (stat(filename, &fst) < 0)           ereport(ERROR,                   (errcode_for_file_access(),
      errmsg("could not stat file \"%s\": %m", filename)));
 
       dirsize += fst.st_size;   }

I'm wondering if the code should check for ENOENT if stat() fails
and either skip this entry silently under the assumption that the
file had been deleted since the call to ReadDir(), or issue a warning
without failing.

-- 
Michael Fuhr


pgsql-hackers by date:

Previous
From: "Simon Riggs"
Date:
Subject: Re: [PATCHES] scan_recycle_buffers
Next
From: "Pavel Stehule"
Date:
Subject: what can be wrong? backport plpgpsm to 8.1