Race condition in pg_database_size()

From: Michael Fuhr <mike(at)fuhr(dot)org>
To: pgsql-hackers(at)postgresql(dot)org
Subject: Race condition in pg_database_size()
Date: 2007-03-10 16:31:00
Message-ID: 20070310163100.GA91660@winnie.fuhr.org
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: 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

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Pavel Stehule 2007-03-10 16:44:52 what can be wrong? backport plpgpsm to 8.1
Previous Message Simon Riggs 2007-03-10 13:34:36 Re: [PATCHES] scan_recycle_buffers