In response to Tom Lane <[EMAIL PROTECTED]>:
> Bill Moran <[EMAIL PROTECTED]> writes:
> > Andrew Dunstan <[EMAIL PROTECTED]> wrote:
> >>> Might be more robust to say
> >>> if (trace_temp_files >= 0)
>
> > I specified in the GUC config that minimum allowable value is -1.
>
> I'd still tend to go with Andrew's suggestion because it makes this
> particular bit of code self-defending against bad values. Yes, it's
> reasonably safe given that bit of coding way over yonder in guc.c,
> but there's no particularly good reason why this code has to depend
> on that to avoid doing something stupid. And it's easier to understand
> too --- you don't have to go looking in guc.c to convince yourself it's
> safe.
Ahh ... well, I've probably already argued about it more than it's worth.
The patch is easy enough to adjust, find attached.
--
Bill Moran
Collaborative Fusion Inc.
diff -c -r src.orig/backend/storage/file/fd.c src/backend/storage/file/fd.c
*** src.orig/backend/storage/file/fd.c Thu Dec 7 15:44:42 2006
--- src/backend/storage/file/fd.c Wed Jan 3 15:05:54 2007
***************
*** 50,55 ****
--- 50,56 ----
#include "access/xact.h"
#include "storage/fd.h"
#include "storage/ipc.h"
+ #include "utils/guc.h"
/*
***************
*** 938,944 ****
void
FileClose(File file)
{
! Vfd *vfdP;
Assert(FileIsValid(file));
--- 939,946 ----
void
FileClose(File file)
{
! Vfd *vfdP;
! struct stat filestats;
Assert(FileIsValid(file));
***************
*** 968,973 ****
--- 970,992 ----
{
/* reset flag so that die() interrupt won't cause problems */
vfdP->fdstate &= ~FD_TEMPORARY;
+ PG_TRACE1(temp__file__cleanup, vfdP->fileName);
+ if (trace_temp_files >= 0)
+ {
+ if (stat(vfdP->fileName, &filestats) == 0)
+ {
+ if (filestats.st_size >= trace_temp_files)
+ {
+ ereport(LOG,
+ (errmsg("temp file: size %lu path \"%s\"",
+ filestats.st_size, vfdP->fileName)));
+ }
+ }
+ else
+ {
+ elog(LOG, "Could not stat \"%s\": %m", vfdP->fileName);
+ }
+ }
if (unlink(vfdP->fileName))
elog(LOG, "failed to unlink \"%s\": %m",
vfdP->fileName);
diff -c -r src.orig/backend/utils/misc/guc.c src/backend/utils/misc/guc.c
*** src.orig/backend/utils/misc/guc.c Wed Nov 29 09:50:07 2006
--- src/backend/utils/misc/guc.c Wed Jan 3 13:51:14 2007
***************
*** 180,186 ****
int log_min_messages = NOTICE;
int client_min_messages = NOTICE;
int log_min_duration_statement = -1;
!
int num_temp_buffers = 1000;
char *ConfigFileName;
--- 180,187 ----
int log_min_messages = NOTICE;
int client_min_messages = NOTICE;
int log_min_duration_statement = -1;
! int trace_temp_files = -1;
!
int num_temp_buffers = 1000;
char *ConfigFileName;
***************
*** 1471,1477 ****
&log_min_duration_statement,
-1, -1, INT_MAX / 1000, NULL, NULL
},
!
{
{"bgwriter_delay", PGC_SIGHUP, RESOURCES,
gettext_noop("Background writer sleep time between rounds in milliseconds"),
--- 1472,1478 ----
&log_min_duration_statement,
-1, -1, INT_MAX / 1000, NULL, NULL
},
!
{
{"bgwriter_delay", PGC_SIGHUP, RESOURCES,
gettext_noop("Background writer sleep time between rounds in milliseconds"),
***************
*** 1657,1662 ****
--- 1658,1673 ----
},
&server_version_num,
PG_VERSION_NUM, PG_VERSION_NUM, PG_VERSION_NUM, NULL, NULL
+ },
+
+ {
+ {"trace_temp_files", PGC_USERSET, LOGGING_WHAT,
+ gettext_noop("Log the use of temp files larger than this size."),
+ gettext_noop("Size and location of each temp file is reported."),
+ NULL
+ },
+ &trace_temp_files,
+ -1, -1, INT_MAX, NULL, NULL
},
/* End-of-list marker */
diff -c -r src.orig/backend/utils/misc/postgresql.conf.sample src/backend/utils/misc/postgresql.conf.sample
*** src.orig/backend/utils/misc/postgresql.conf.sample Mon Nov 20 20:23:37 2006
--- src/backend/utils/misc/postgresql.conf.sample Wed Jan 3 11:05:48 2007
***************
*** 333,338 ****
--- 333,341 ----
#log_statement = 'none' # none, ddl, mod, all
#log_hostname = off
+ #trace_temp_files = -1 # Log usage of temporary files larger than
+ # the specified size (in bytes). -1 disables.
+ # 0 effectively logs all temp file usage.
#---------------------------------------------------------------------------
# RUNTIME STATISTICS
diff -c -r src.orig/include/utils/guc.h src/include/utils/guc.h
*** src.orig/include/utils/guc.h Thu Oct 19 14:32:47 2006
--- src/include/utils/guc.h Wed Jan 3 13:45:52 2007
***************
*** 123,128 ****
--- 123,129 ----
extern int log_min_messages;
extern int client_min_messages;
extern int log_min_duration_statement;
+ extern int trace_temp_files;
extern int num_temp_buffers;
---------------------------(end of broadcast)---------------------------
TIP 7: You can help support the PostgreSQL project by donating at
http://www.postgresql.org/about/donate