Skip to content

Commit a649174

Browse files
gfphoenix78avamingli
authored andcommitted
Fix calculating size of a database or tablespace
pg_database_size only counts phyical files in database directory. The sub-directory under database directory can't represent the real storage size. The same issue happens on calculating the size of tablespace as well. Currently, PAX creates a separate directory to storage all its phyical files, like micro-partition files, visibility-map files, etc. To include the phyical files occupied by PAX tables, `db_dir_size` should calculate its sub-directories recursively.
1 parent 1e13f60 commit a649174

File tree

1 file changed

+9
-0
lines changed

1 file changed

+9
-0
lines changed

src/backend/utils/adt/dbsize.c

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -153,6 +153,15 @@ db_dir_size(const char *path)
153153
continue;
154154

155155
snprintf(filename, sizeof(filename), "%s/%s", path, direntry->d_name);
156+
if (direntry->d_type == DT_DIR)
157+
{
158+
/**
159+
* Recurse into subdirectory. PAX stores data file in a separate
160+
* directory, so we need to account for that.
161+
*/
162+
dirsize += db_dir_size(filename);
163+
continue;
164+
}
156165

157166
if (stat(filename, &fst) < 0)
158167
{

0 commit comments

Comments
 (0)