/* * Remove temporary files left over from a prior postmaster session * * This should be called during postmaster startup. It will forcibly * remove any leftover files created by OpenTemporaryFile. * * NOTE: we could, but don't, call this during a post-backend-crash restart * cycle. The argument for not doing it is that someone might want to examine * the temp files for debugging purposes. This does however mean that * OpenTemporaryFile had better allow for collision with an existing temp * file name. */ void RemovePgTempFiles(void) { char temp_path[MAXPGPATH]; DIR *spc_dir; struct dirent *spc_de; /* * First process temp files in pg_default ($PGDATA/base) */ snprintf(temp_path, sizeof(temp_path), "base/%s", PG_TEMP_FILES_DIR); RemovePgTempFilesInDir(temp_path); /* * Cycle through temp directories for all non-default tablespaces. */ spc_dir = AllocateDir("pg_tblspc"); while ((spc_de = ReadDir(spc_dir, "pg_tblspc")) != NULL) { if (strcmp(spc_de->d_name, ".") == 0 || strcmp(spc_de->d_name, "..") == 0) continue; snprintf(temp_path, sizeof(temp_path), "pg_tblspc/%s/%s", spc_de->d_name, PG_TEMP_FILES_DIR); RemovePgTempFilesInDir(temp_path); } FreeDir(spc_dir); /* * In EXEC_BACKEND case there is a pgsql_tmp directory at the top level of * DataDir as well. */ #ifdef EXEC_BACKEND RemovePgTempFilesInDir(PG_TEMP_FILES_DIR); #endif }
/* * Remove temporary files left over from a prior postmaster session * * This should be called during postmaster startup. It will forcibly * remove any leftover files created by OpenTemporaryFile. * * We also call this during the post-backend-crash restart cycle * (postmaster reset). */ void RemovePgTempFiles(void) { char temp_path[MAXPGPATH]; DIR *db_dir; struct dirent *db_de; ereport(LOG, (errmsg("removing all temporary files"))); /* * Cycle through pgsql_tmp directories for all databases and remove old * temp files. */ db_dir = AllocateDir("base"); while ((db_de = ReadDir(db_dir, "base")) != NULL) { if (strcmp(db_de->d_name, ".") == 0 || strcmp(db_de->d_name, "..") == 0) continue; snprintf(temp_path, sizeof(temp_path), "base/%s/%s", db_de->d_name, PG_TEMP_FILES_DIR); RemovePgTempFilesInDir(temp_path); } FreeDir(db_dir); /* * In EXEC_BACKEND case there is a pgsql_tmp directory at the top level of * DataDir as well. */ #ifdef EXEC_BACKEND RemovePgTempFilesInDir(PG_TEMP_FILES_DIR); #endif }