• Tom Lane's avatar
    Restructure local-buffer handling per recent pghackers discussion. · 5df307c7
    Tom Lane authored
    The local buffer manager is no longer used for newly-created relations
    (unless they are TEMP); a new non-TEMP relation goes through the shared
    bufmgr and thus will participate normally in checkpoints.  But TEMP relations
    use the local buffer manager throughout their lifespan.  Also, operations
    in TEMP relations are not logged in WAL, thus improving performance.
    Since it's no longer necessary to fsync relations as they move out of the
    local buffers into shared buffers, quite a lot of smgr.c/md.c/fd.c code
    is no longer needed and has been removed: there's no concept of a dirty
    relation anymore in md.c/fd.c, and we never fsync anything but WAL.
    Still TODO: improve local buffer management algorithms so that it would
    be reasonable to increase NLocBuffer.
    5df307c7
fd.h 2.27 KB
/*-------------------------------------------------------------------------
 *
 * fd.h
 *	  Virtual file descriptor definitions.
 *
 *
 * Portions Copyright (c) 1996-2002, PostgreSQL Global Development Group
 * Portions Copyright (c) 1994, Regents of the University of California
 *
 * $Id: fd.h,v 1.36 2002/08/06 02:36:35 tgl Exp $
 *
 *-------------------------------------------------------------------------
 */

/*
 * calls:
 *
 *	File {Close, Read, Write, Seek, Tell, MarkDirty, 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.
 */
#ifndef FD_H
#define FD_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 FileNameOpenFile(FileName fileName, int fileFlags, int fileMode);
extern File PathNameOpenFile(FileName fileName, int fileFlags, int fileMode);
extern File OpenTemporaryFile(void);
extern void FileClose(File file);
extern void FileUnlink(File file);
extern int	FileRead(File file, char *buffer, int amount);
extern int	FileWrite(File file, char *buffer, int amount);
extern long FileSeek(File file, long offset, int whence);
extern int	FileTruncate(File file, long offset);

/* Operations that allow use of regular stdio --- USE WITH CAUTION */
extern FILE *AllocateFile(char *name, char *mode);
extern void FreeFile(FILE *);

/* 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 closeAllVfds(void);
extern void AtEOXact_Files(void);
extern void RemovePgTempFiles(void);
extern int	pg_fsync(int fd);
extern int	pg_fdatasync(int fd);

#endif   /* FD_H */