1/*-------------------------------------------------------------------------
4 * Management of named temporary files.
6 * Portions Copyright (c) 1996-2025, PostgreSQL Global Development Group
7 * Portions Copyright (c) 1994, Regents of the University of California
10 * src/backend/storage/file/fileset.c
12 * FileSets provide a temporary namespace (think directory) so that files can
13 * be discovered by name.
15 * FileSets can be used by backends when the temporary files need to be
16 * opened/closed multiple times and the underlying files need to survive across
19 *-------------------------------------------------------------------------
37 * Initialize a space for temporary files. This API can be used by shared
38 * fileset as well as if the temporary files are used only by single backend
39 * but the files need to be opened and closed multiple times and also the
40 * underlying files need to survive across transactions.
42 * The callers are expected to explicitly remove such files by using
43 * FileSetDelete/FileSetDeleteAll.
45 * Files will be distributed over the tablespaces configured in
48 * Under the covers the set is one or more directories which will eventually
58 counter = (counter + 1) % INT_MAX;
60 /* Capture the tablespace OIDs so that all backends agree on them. */
67 /* If the GUC is empty, use current database's default tablespace */
76 * An entry of InvalidOid means use the default tablespace for the
77 * current database. Replace that now, to be sure that all users of
78 * the FileSet agree on what to do.
89 * Create a new file in the given set.
100 /* If we failed, see if we need to create the directory on demand. */
117 * Open a file that was created with FileSetCreate() */
131 * Delete a file that was created with FileSetCreate().
133 * Return true if the file existed, false if didn't.
137 bool error_on_failure)
147 * Delete all files in the set.
156 * Delete the directory we created in each tablespace. Doesn't fail
157 * because we use this in error cleanup paths, but can generate LOG
158 * message on IO error.
168 * Build the path for the directory holding the files backing a FileSet in a
183 * Sorting has to determine which tablespace a given temporary file belongs in.
194 * Compute the full path of a file in a FileSet.
void PrepareTempTablespaces(void)
int GetTempTablespaces(Oid *tableSpaces, int numSpaces)
File PathNameOpenTemporaryFile(const char *path, int mode)
File PathNameCreateTemporaryFile(const char *path, bool error_on_failure)
void PathNameDeleteTemporaryDir(const char *dirname)
bool PathNameDeleteTemporaryFile(const char *path, bool error_on_failure)
void PathNameCreateTemporaryDir(const char *basedir, const char *directory)
void TempTablespacePath(char *path, Oid tablespace)
#define PG_TEMP_FILE_PREFIX
File FileSetOpen(FileSet *fileset, const char *name, int mode)
bool FileSetDelete(FileSet *fileset, const char *name, bool error_on_failure)
static void FilePath(char *path, FileSet *fileset, const char *name)
void FileSetInit(FileSet *fileset)
void FileSetDeleteAll(FileSet *fileset)
static void FileSetPath(char *path, FileSet *fileset, Oid tablespace)
static Oid ChooseTablespace(const FileSet *fileset, const char *name)
File FileSetCreate(FileSet *fileset, const char *name)
uint32 hash_bytes(const unsigned char *k, int keylen)
static PgChecksumMode mode
static unsigned hash(unsigned *uv, int n)