Index: src/backend/postmaster/postmaster.c =================================================================== RCS file: /home/projects/pgsql/cvsroot/pgsql/src/backend/postmaster/postmaster.c,v retrieving revision 1.212 diff -c -r1.212 postmaster.c *** src/backend/postmaster/postmaster.c 2001/04/19 19:09:23 1.212 --- src/backend/postmaster/postmaster.c 2001/05/23 00:31:42 *************** *** 243,248 **** --- 243,249 ---- static void SignalChildren(int signal); static int CountChildren(void); static bool CreateOptsFile(int argc, char *argv[]); + static void RemovePgSorttemp(void); static pid_t SSDataBase(int xlop); *************** *** 595,600 **** --- 596,604 ---- if (!CreateDataDirLockFile(DataDir, true)) ExitPostmaster(1); + /* Remove old sort files */ + RemovePgSorttemp(); + /* * Establish input sockets. */ *************** *** 2449,2452 **** --- 2453,2474 ---- fclose(fp); return true; + } + + + /* + * Remove old sort files + */ + static void + RemovePgSorttemp(void) + { + char clear_pg_sorttemp[1024]; + + /* Don't remove directory in case it is a symlink */ + snprintf(clear_pg_sorttemp, sizeof(clear_pg_sorttemp), + "find \"%s\"/base -name pg_sorttemp -type d -exec sh -c \"rm -f {}/*\" \\;", + DataDir); + /* Make sure we have the full 'find' command */ + if (strlen(clear_pg_sorttemp)+1 < 1024) + system(clear_pg_sorttemp); } Index: src/backend/storage/file/fd.c =================================================================== RCS file: /home/projects/pgsql/cvsroot/pgsql/src/backend/storage/file/fd.c,v retrieving revision 1.76 diff -c -r1.76 fd.c *** src/backend/storage/file/fd.c 2001/04/03 04:07:02 1.76 --- src/backend/storage/file/fd.c 2001/05/23 00:31:42 *************** *** 90,95 **** --- 90,97 ---- #define VFD_CLOSED (-1) + #define TEMP_SORT_DIR "pg_sorttemp" + #define FileIsValid(file) \ ((file) > 0 && (file) < (int) SizeVfdCache && VfdCache[file].fileName != NULL) *************** *** 742,762 **** File OpenTemporaryFile(void) { ! char tempfilename[64]; File file; /* * Generate a tempfile name that's unique within the current * transaction */ ! snprintf(tempfilename, sizeof(tempfilename), ! "pg_sorttemp%d.%ld", MyProcPid, tempFileCounter++); /* Open the file */ ! file = FileNameOpenFile(tempfilename, O_RDWR | O_CREAT | O_TRUNC | PG_BINARY, 0600); if (file <= 0) ! elog(ERROR, "Failed to create temporary file %s", tempfilename); /* Mark it for deletion at close or EOXact */ VfdCache[file].fdstate |= FD_TEMPORARY; --- 744,772 ---- File OpenTemporaryFile(void) { ! char tempfilepath[128]; File file; /* * Generate a tempfile name that's unique within the current * transaction */ ! snprintf(tempfilepath, sizeof(tempfilepath), ! "%s%c%d.%ld", TEMP_SORT_DIR, SEP_CHAR, MyProcPid, ! tempFileCounter++); /* Open the file */ ! file = FileNameOpenFile(tempfilepath, O_RDWR | O_CREAT | O_TRUNC | PG_BINARY, 0600); if (file <= 0) ! { ! /* mkdir could fail if some one else already created it */ ! mkdir(TEMP_SORT_DIR, S_IRWXU); ! file = FileNameOpenFile(tempfilepath, ! O_RDWR | O_CREAT | O_TRUNC | PG_BINARY, 0600); ! if (file <= 0) ! elog(ERROR, "Failed to create temporary file %s", tempfilepath); ! } /* Mark it for deletion at close or EOXact */ VfdCache[file].fdstate |= FD_TEMPORARY;