Skip to content

Commit 576027b

Browse files
committed
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.
1 parent 5acde74 commit 576027b

File tree

1 file changed

+17
-8
lines changed

1 file changed

+17
-8
lines changed

src/backend/utils/adt/dbsize.c

Lines changed: 17 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
* Copyright (c) 2002-2007, PostgreSQL Global Development Group
66
*
77
* IDENTIFICATION
8-
* $PostgreSQL: pgsql/src/backend/utils/adt/dbsize.c,v 1.11 2007/02/27 23:48:07 tgl Exp $
8+
* $PostgreSQL: pgsql/src/backend/utils/adt/dbsize.c,v 1.12 2007/03/11 05:22:00 alvherre Exp $
99
*
1010
*/
1111

@@ -52,10 +52,14 @@ db_dir_size(const char *path)
5252
snprintf(filename, MAXPGPATH, "%s/%s", path, direntry->d_name);
5353

5454
if (stat(filename, &fst) < 0)
55-
ereport(ERROR,
56-
(errcode_for_file_access(),
57-
errmsg("could not stat file \"%s\": %m", filename)));
58-
55+
{
56+
if (errno == ENOENT)
57+
continue;
58+
else
59+
ereport(ERROR,
60+
(errcode_for_file_access(),
61+
errmsg("could not stat file \"%s\": %m", filename)));
62+
}
5963
dirsize += fst.st_size;
6064
}
6165

@@ -174,9 +178,14 @@ calculate_tablespace_size(Oid tblspcOid)
174178
snprintf(pathname, MAXPGPATH, "%s/%s", tblspcPath, direntry->d_name);
175179

176180
if (stat(pathname, &fst) < 0)
177-
ereport(ERROR,
178-
(errcode_for_file_access(),
179-
errmsg("could not stat file \"%s\": %m", pathname)));
181+
{
182+
if (errno == ENOENT)
183+
continue;
184+
else
185+
ereport(ERROR,
186+
(errcode_for_file_access(),
187+
errmsg("could not stat file \"%s\": %m", pathname)));
188+
}
180189

181190
if (fst.st_mode & S_IFDIR)
182191
totalsize += db_dir_size(pathname);

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy