Skip site navigation (1) Skip section navigation (2)

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: (view raw, whole thread or download thread mbox)
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)

        snprintf(filename, MAXPGPATH, "%s/%s", path, direntry->d_name);

        if (stat(filename, &fst) < 0)
                     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

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

Privacy Policy | About PostgreSQL
Copyright © 1996-2017 The PostgreSQL Global Development Group