1
0
mirror of https://github.com/postgres/postgres.git synced 2025-07-02 09:02:37 +03:00

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
This commit is contained in:
Magnus Hagander
2012-01-26 14:41:19 +01:00
parent 9d35116611
commit bc3347484a
9 changed files with 150 additions and 25 deletions

View File

@ -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)
/* 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);
/* and last report the stat results */
if (stat_errno == 0)
{
struct stat filestats;
int stat_errno;
pgstat_report_tempfile(filestats.st_size);
/* 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);
/* 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 */