diff options
author | Alvaro Herrera <alvherre@alvh.no-ip.org> | 2007-03-11 06:44:11 +0000 |
---|---|---|
committer | Alvaro Herrera <alvherre@alvh.no-ip.org> | 2007-03-11 06:44:11 +0000 |
commit | 8a7b38617a5e1390dc993faf3c86c82d2202de15 (patch) | |
tree | 7bd5936d0405e404046f795ed54cb9abef2121ff /src/backend/utils/adt/dbsize.c | |
parent | 5ea7b175f6e123d604e3cb11303f0dcf194a7b9b (diff) |
Fix a race condition that caused pg_database_size() and pg_tablespace_size()
to fail if an object was removed between calls to ReadDir() and stat().
Per discussion in pgsql-hackers.
http://archives.postgresql.org/pgsql-hackers/2007-03/msg00671.php
Bug report and patch by Michael Fuhr.
Diffstat (limited to 'src/backend/utils/adt/dbsize.c')
-rw-r--r-- | src/backend/utils/adt/dbsize.c | 25 |
1 files changed, 17 insertions, 8 deletions
diff --git a/src/backend/utils/adt/dbsize.c b/src/backend/utils/adt/dbsize.c index fa8b13787e5..dc27e249f3f 100644 --- a/src/backend/utils/adt/dbsize.c +++ b/src/backend/utils/adt/dbsize.c @@ -5,7 +5,7 @@ * Copyright (c) 2002-2006, PostgreSQL Global Development Group * * IDENTIFICATION - * $PostgreSQL: pgsql/src/backend/utils/adt/dbsize.c,v 1.9 2006/11/06 03:06:41 tgl Exp $ + * $PostgreSQL: pgsql/src/backend/utils/adt/dbsize.c,v 1.9.2.1 2007/03/11 06:44:11 alvherre Exp $ * */ @@ -52,10 +52,14 @@ db_dir_size(const char *path) 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))); - + { + if (errno == ENOENT) + continue; + else + ereport(ERROR, + (errcode_for_file_access(), + errmsg("could not stat file \"%s\": %m", filename))); + } dirsize += fst.st_size; } @@ -174,9 +178,14 @@ calculate_tablespace_size(Oid tblspcOid) snprintf(pathname, MAXPGPATH, "%s/%s", tblspcPath, direntry->d_name); if (stat(pathname, &fst) < 0) - ereport(ERROR, - (errcode_for_file_access(), - errmsg("could not stat file \"%s\": %m", pathname))); + { + if (errno == ENOENT) + continue; + else + ereport(ERROR, + (errcode_for_file_access(), + errmsg("could not stat file \"%s\": %m", pathname))); + } if (fst.st_mode & S_IFDIR) totalsize += db_dir_size(pathname); |