mirror of
https://github.com/postgres/postgres.git
synced 2026-06-17 22:19:08 -04:00
fba105b109
"Blind writes" are a mechanism to push buffers down to disk when evicting them; since they may belong to different databases than the one a backend is connected to, the backend does not necessarily have a relation to link them to, and thus no way to blow them away. We were keeping those files open indefinitely, which would cause a problem if the underlying table was deleted, because the operating system would not be able to reclaim the disk space used by those files. To fix, have bufmgr mark such files as transient to smgr; the lower layer is allowed to close the file descriptor when the current transaction ends. We must be careful to have any other access of the file to remove the transient markings, to prevent unnecessary expensive system calls when evicting buffers belonging to our own database (which files we're likely to require again soon.) This commit fixes a bug in the previous one, which neglected to cleanly handle the LRU ring that fd.c uses to manage open files, and caused an unacceptable failure just before beta2 and was thus reverted.
109 lines
3.2 KiB
C
109 lines
3.2 KiB
C
/*-------------------------------------------------------------------------
|
|
*
|
|
* fd.h
|
|
* Virtual file descriptor definitions.
|
|
*
|
|
*
|
|
* Portions Copyright (c) 1996-2011, PostgreSQL Global Development Group
|
|
* Portions Copyright (c) 1994, Regents of the University of California
|
|
*
|
|
* src/include/storage/fd.h
|
|
*
|
|
*-------------------------------------------------------------------------
|
|
*/
|
|
|
|
/*
|
|
* calls:
|
|
*
|
|
* File {Close, Read, Write, Seek, Tell, Sync}
|
|
* {File Name Open, Allocate, Free} File
|
|
*
|
|
* These are NOT JUST RENAMINGS OF THE UNIX ROUTINES.
|
|
* Use them for all file activity...
|
|
*
|
|
* File fd;
|
|
* fd = FilePathOpenFile("foo", O_RDONLY, 0600);
|
|
*
|
|
* AllocateFile();
|
|
* FreeFile();
|
|
*
|
|
* Use AllocateFile, not fopen, if you need a stdio file (FILE*); then
|
|
* use FreeFile, not fclose, to close it. AVOID using stdio for files
|
|
* that you intend to hold open for any length of time, since there is
|
|
* no way for them to share kernel file descriptors with other files.
|
|
*
|
|
* Likewise, use AllocateDir/FreeDir, not opendir/closedir, to allocate
|
|
* open directories (DIR*).
|
|
*/
|
|
#ifndef FD_H
|
|
#define FD_H
|
|
|
|
#include <dirent.h>
|
|
|
|
|
|
/*
|
|
* FileSeek uses the standard UNIX lseek(2) flags.
|
|
*/
|
|
|
|
typedef char *FileName;
|
|
|
|
typedef int File;
|
|
|
|
|
|
/* GUC parameter */
|
|
extern int max_files_per_process;
|
|
|
|
|
|
/*
|
|
* prototypes for functions in fd.c
|
|
*/
|
|
|
|
/* Operations on virtual Files --- equivalent to Unix kernel file ops */
|
|
extern File PathNameOpenFile(FileName fileName, int fileFlags, int fileMode);
|
|
extern File OpenTemporaryFile(bool interXact);
|
|
extern void FileSetTransient(File file);
|
|
extern void FileClose(File file);
|
|
extern int FilePrefetch(File file, off_t offset, int amount);
|
|
extern int FileRead(File file, char *buffer, int amount);
|
|
extern int FileWrite(File file, char *buffer, int amount);
|
|
extern int FileSync(File file);
|
|
extern off_t FileSeek(File file, off_t offset, int whence);
|
|
extern int FileTruncate(File file, off_t offset);
|
|
extern char *FilePathName(File file);
|
|
|
|
/* Operations that allow use of regular stdio --- USE WITH CAUTION */
|
|
extern FILE *AllocateFile(const char *name, const char *mode);
|
|
extern int FreeFile(FILE *file);
|
|
|
|
/* Operations to allow use of the <dirent.h> library routines */
|
|
extern DIR *AllocateDir(const char *dirname);
|
|
extern struct dirent *ReadDir(DIR *dir, const char *dirname);
|
|
extern int FreeDir(DIR *dir);
|
|
|
|
/* If you've really really gotta have a plain kernel FD, use this */
|
|
extern int BasicOpenFile(FileName fileName, int fileFlags, int fileMode);
|
|
|
|
/* Miscellaneous support routines */
|
|
extern void InitFileAccess(void);
|
|
extern void set_max_safe_fds(void);
|
|
extern void closeAllVfds(void);
|
|
extern void SetTempTablespaces(Oid *tableSpaces, int numSpaces);
|
|
extern bool TempTablespacesAreSet(void);
|
|
extern Oid GetNextTempTableSpace(void);
|
|
extern void AtEOXact_Files(void);
|
|
extern void AtEOSubXact_Files(bool isCommit, SubTransactionId mySubid,
|
|
SubTransactionId parentSubid);
|
|
extern void RemovePgTempFiles(void);
|
|
|
|
extern int pg_fsync(int fd);
|
|
extern int pg_fsync_no_writethrough(int fd);
|
|
extern int pg_fsync_writethrough(int fd);
|
|
extern int pg_fdatasync(int fd);
|
|
extern int pg_flush_data(int fd, off_t offset, off_t amount);
|
|
|
|
/* Filename components for OpenTemporaryFile */
|
|
#define PG_TEMP_FILES_DIR "pgsql_tmp"
|
|
#define PG_TEMP_FILE_PREFIX "pgsql_tmp"
|
|
|
|
#endif /* FD_H */
|