aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorBruce Momjian <bruce@momjian.us>2007-01-09 21:31:17 +0000
committerBruce Momjian <bruce@momjian.us>2007-01-09 21:31:17 +0000
commitbe8a4318815640ff57afc775f118367c9a1241a8 (patch)
treeb3340d1b7d871383c9b3bd68f6fcb8d3dc33d84f /src
parent1e0bf9041ebb5cf80e83c48fd06214c5d6e22c17 (diff)
downloadpostgresql-be8a4318815640ff57afc775f118367c9a1241a8.tar.gz
postgresql-be8a4318815640ff57afc775f118367c9a1241a8.zip
Add GUC log_temp_files to log the use of temporary files.
Bill Moran
Diffstat (limited to 'src')
-rw-r--r--src/backend/storage/file/fd.c19
-rw-r--r--src/backend/utils/misc/guc.c13
-rw-r--r--src/backend/utils/misc/postgresql.conf.sample3
-rw-r--r--src/include/utils/guc.h3
4 files changed, 34 insertions, 4 deletions
diff --git a/src/backend/storage/file/fd.c b/src/backend/storage/file/fd.c
index 693c2e80141..a485189f1ea 100644
--- a/src/backend/storage/file/fd.c
+++ b/src/backend/storage/file/fd.c
@@ -7,7 +7,7 @@
* Portions Copyright (c) 1994, Regents of the University of California
*
* IDENTIFICATION
- * $PostgreSQL: pgsql/src/backend/storage/file/fd.c,v 1.132 2007/01/05 22:19:37 momjian Exp $
+ * $PostgreSQL: pgsql/src/backend/storage/file/fd.c,v 1.133 2007/01/09 21:31:14 momjian Exp $
*
* NOTES:
*
@@ -50,6 +50,7 @@
#include "access/xact.h"
#include "storage/fd.h"
#include "storage/ipc.h"
+#include "utils/guc.h"
/*
@@ -938,7 +939,8 @@ OpenTemporaryFile(bool interXact)
void
FileClose(File file)
{
- Vfd *vfdP;
+ Vfd *vfdP;
+ struct stat filestats;
Assert(FileIsValid(file));
@@ -968,6 +970,19 @@ FileClose(File file)
{
/* reset flag so that die() interrupt won't cause problems */
vfdP->fdstate &= ~FD_TEMPORARY;
+ PG_TRACE1(temp__file__cleanup, vfdP->fileName);
+ if (log_temp_files >= 0)
+ {
+ if (stat(vfdP->fileName, &filestats) == 0)
+ {
+ if (filestats.st_size >= log_temp_files)
+ ereport(LOG,
+ (errmsg("temp file: path \"%s\" size %lu",
+ vfdP->fileName, (unsigned long)filestats.st_size)));
+ }
+ else
+ elog(LOG, "Could not stat \"%s\": %m", vfdP->fileName);
+ }
if (unlink(vfdP->fileName))
elog(LOG, "failed to unlink \"%s\": %m",
vfdP->fileName);
diff --git a/src/backend/utils/misc/guc.c b/src/backend/utils/misc/guc.c
index e2ad24f7f4f..4d4ef07d2c7 100644
--- a/src/backend/utils/misc/guc.c
+++ b/src/backend/utils/misc/guc.c
@@ -10,7 +10,7 @@
* Written by Peter Eisentraut <peter_e@gmx.net>.
*
* IDENTIFICATION
- * $PostgreSQL: pgsql/src/backend/utils/misc/guc.c,v 1.365 2007/01/05 22:19:46 momjian Exp $
+ * $PostgreSQL: pgsql/src/backend/utils/misc/guc.c,v 1.366 2007/01/09 21:31:14 momjian Exp $
*
*--------------------------------------------------------------------
*/
@@ -182,6 +182,7 @@ int log_min_error_statement = ERROR;
int log_min_messages = NOTICE;
int client_min_messages = NOTICE;
int log_min_duration_statement = -1;
+int log_temp_files = -1;
int num_temp_buffers = 1000;
@@ -1660,6 +1661,16 @@ static struct config_int ConfigureNamesInt[] =
&server_version_num,
PG_VERSION_NUM, PG_VERSION_NUM, PG_VERSION_NUM, NULL, NULL
},
+
+ {
+ {"log_temp_files", PGC_USERSET, LOGGING_WHAT,
+ gettext_noop("Log the use of temporary files larger than this size."),
+ gettext_noop("Zero logs all files. The default is -1 (turning this feature off)."),
+ NULL
+ },
+ &log_temp_files,
+ -1, -1, INT_MAX, NULL, NULL
+ },
/* End-of-list marker */
{
diff --git a/src/backend/utils/misc/postgresql.conf.sample b/src/backend/utils/misc/postgresql.conf.sample
index 196cae54a36..989126477d1 100644
--- a/src/backend/utils/misc/postgresql.conf.sample
+++ b/src/backend/utils/misc/postgresql.conf.sample
@@ -333,6 +333,9 @@
#log_statement = 'none' # none, ddl, mod, all
#log_hostname = off
+#log_temp_files = -1 # Log temporary files equal or larger
+ # than the specified number of bytes.
+ # -1 disables; 0 logs all temp files
#---------------------------------------------------------------------------
# RUNTIME STATISTICS
diff --git a/src/include/utils/guc.h b/src/include/utils/guc.h
index e1fc64e8689..d324d66c22a 100644
--- a/src/include/utils/guc.h
+++ b/src/include/utils/guc.h
@@ -7,7 +7,7 @@
* Copyright (c) 2000-2007, PostgreSQL Global Development Group
* Written by Peter Eisentraut <peter_e@gmx.net>.
*
- * $PostgreSQL: pgsql/src/include/utils/guc.h,v 1.77 2007/01/05 22:19:59 momjian Exp $
+ * $PostgreSQL: pgsql/src/include/utils/guc.h,v 1.78 2007/01/09 21:31:17 momjian Exp $
*--------------------------------------------------------------------
*/
#ifndef GUC_H
@@ -123,6 +123,7 @@ extern int log_min_error_statement;
extern int log_min_messages;
extern int client_min_messages;
extern int log_min_duration_statement;
+extern int log_temp_files;
extern int num_temp_buffers;