diff options
author | Magnus Hagander <magnus@hagander.net> | 2012-01-26 14:41:19 +0100 |
---|---|---|
committer | Magnus Hagander <magnus@hagander.net> | 2012-01-26 14:41:19 +0100 |
commit | bc3347484a7bf9eddb98e4352d84599cae9a31c6 (patch) | |
tree | f362d4e7f8e1f1d5f1fe318bd796e4e86d5d2abd /src/backend/storage/file/fd.c | |
parent | 9d35116611e6a1fc10f2298944fbf0e4e1a826be (diff) | |
download | postgresql-bc3347484a7bf9eddb98e4352d84599cae9a31c6.tar.gz postgresql-bc3347484a7bf9eddb98e4352d84599cae9a31c6.zip |
Track temporary file count and size in pg_stat_database
Add counters for number and size of temporary files used
for spill-to-disk queries for each database to the
pg_stat_database view.
Tomas Vondra, review by Magnus Hagander
Diffstat (limited to 'src/backend/storage/file/fd.c')
-rw-r--r-- | src/backend/storage/file/fd.c | 36 |
1 files changed, 16 insertions, 20 deletions
diff --git a/src/backend/storage/file/fd.c b/src/backend/storage/file/fd.c index 43bc43ab10f..673b25db347 100644 --- a/src/backend/storage/file/fd.c +++ b/src/backend/storage/file/fd.c @@ -1088,6 +1088,9 @@ FileClose(File file) */ if (vfdP->fdstate & FD_TEMPORARY) { + struct stat filestats; + int stat_errno; + /* * If we get an error, as could happen within the ereport/elog calls, * we'll come right back here during transaction abort. Reset the @@ -1101,23 +1104,22 @@ FileClose(File file) temporary_files_size -= vfdP->fileSize; vfdP->fileSize = 0; - if (log_temp_files >= 0) - { - struct stat filestats; - int stat_errno; + /* first try the stat() */ + if (stat(vfdP->fileName, &filestats)) + stat_errno = errno; + else + stat_errno = 0; - /* first try the stat() */ - if (stat(vfdP->fileName, &filestats)) - stat_errno = errno; - else - stat_errno = 0; + /* in any case do the unlink */ + if (unlink(vfdP->fileName)) + elog(LOG, "could not unlink file \"%s\": %m", vfdP->fileName); - /* in any case do the unlink */ - if (unlink(vfdP->fileName)) - elog(LOG, "could not unlink file \"%s\": %m", vfdP->fileName); + /* and last report the stat results */ + if (stat_errno == 0) + { + pgstat_report_tempfile(filestats.st_size); - /* and last report the stat results */ - if (stat_errno == 0) + if (log_temp_files >= 0) { if ((filestats.st_size / 1024) >= log_temp_files) ereport(LOG, @@ -1131,12 +1133,6 @@ FileClose(File file) elog(LOG, "could not stat file \"%s\": %m", vfdP->fileName); } } - else - { - /* easy case, just do the unlink */ - if (unlink(vfdP->fileName)) - elog(LOG, "could not unlink file \"%s\": %m", vfdP->fileName); - } } /* Unregister it from the resource owner */ |