aboutsummaryrefslogtreecommitdiff
path: root/src/backend/storage/file/fd.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/backend/storage/file/fd.c')
-rw-r--r--src/backend/storage/file/fd.c68
1 files changed, 62 insertions, 6 deletions
diff --git a/src/backend/storage/file/fd.c b/src/backend/storage/file/fd.c
index 53ba25115a2..486dd06bdc5 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.134 2007/01/09 22:03:51 momjian Exp $
+ * $PostgreSQL: pgsql/src/backend/storage/file/fd.c,v 1.135 2007/01/25 04:35:10 momjian Exp $
*
* NOTES:
*
@@ -46,6 +46,8 @@
#include <unistd.h>
#include <fcntl.h>
+#include "commands/tablespace.h"
+
#include "miscadmin.h"
#include "access/xact.h"
#include "storage/fd.h"
@@ -76,6 +78,7 @@
*/
#define FD_MINFREE 10
+#define OIDCHARS 10 /* max chars printed by %u */
/*
* A number of platforms allow individual processes to open many more files
@@ -880,13 +883,51 @@ OpenTemporaryFile(bool interXact)
{
char tempfilepath[MAXPGPATH];
File file;
+ Oid oid;
+ char *path;
+ int pathlen;
/*
- * Generate a tempfile name that should be unique within the current
- * database instance.
+ * Take a look what should be the path of the temporary file
*/
- snprintf(tempfilepath, sizeof(tempfilepath),
- "%s/%s%d.%ld", PG_TEMP_FILES_DIR, PG_TEMP_FILE_PREFIX,
+ oid = GetTempTablespace();
+ if (oid != InvalidOid)
+ {
+ /*
+ * As we got a valid tablespace, try to create the
+ * file there
+ */
+
+ pathlen = strlen("pg_tblspc/") + OIDCHARS + 1;
+ path = (char *) palloc(pathlen);
+ snprintf(path, pathlen, "pg_tblspc/%u", oid );
+
+ /*
+ * Generate a tempfile name that should be unique within the current
+ * database instance.
+ */
+ snprintf(tempfilepath, sizeof(tempfilepath),
+ "%s/%s%d.%ld", path, PG_TEMP_FILE_PREFIX,
+ MyProcPid, tempFileCounter++);
+ pfree(path);
+ file = PathNameOpenFile(tempfilepath,
+ O_RDWR | O_CREAT | O_TRUNC | PG_BINARY,
+ 0600);
+ }
+
+ /*
+ * Create a normal temporary file if no tablespace returned or
+ * couldn't create the file in the tablespace "oid"
+ */
+ if (oid == InvalidOid || file <= 0)
+ {
+ path = PG_TEMP_FILES_DIR;
+ /*
+ * Generate a tempfile name that should be unique within the current
+ * database instance.
+ */
+ snprintf(tempfilepath, sizeof(tempfilepath),
+ "%s/%s%d.%ld", path, PG_TEMP_FILE_PREFIX,
MyProcPid, tempFileCounter++);
/*
@@ -918,7 +959,8 @@ OpenTemporaryFile(bool interXact)
if (file <= 0)
elog(ERROR, "could not create temporary file \"%s\": %m",
tempfilepath);
- }
+ }
+ }
/* Mark it for deletion at close */
VfdCache[file].fdstate |= FD_TEMPORARY;
@@ -1292,6 +1334,20 @@ TryAgain:
errno = save_errno;
}
+ /*
+ * TEMPORARY hack to log the Windows error code on fopen failures, in
+ * hopes of diagnosing some hard-to-reproduce problems.
+ */
+#ifdef WIN32
+ {
+ int save_errno = errno;
+
+ elog(LOG, "Windows fopen(\"%s\",\"%s\") failed: code %lu, errno %d",
+ name, mode, GetLastError(), save_errno);
+ errno = save_errno;
+ }
+#endif
+
return NULL;
}