Header And Logo

PostgreSQL
| The world's most advanced open source database.

xlogdefs.h

Go to the documentation of this file.
00001 /*
00002  * xlogdefs.h
00003  *
00004  * Postgres transaction log manager record pointer and
00005  * timeline number definitions
00006  *
00007  * Portions Copyright (c) 1996-2013, PostgreSQL Global Development Group
00008  * Portions Copyright (c) 1994, Regents of the University of California
00009  *
00010  * src/include/access/xlogdefs.h
00011  */
00012 #ifndef XLOG_DEFS_H
00013 #define XLOG_DEFS_H
00014 
00015 #include <fcntl.h>              /* need open() flags */
00016 
00017 /*
00018  * Pointer to a location in the XLOG.  These pointers are 64 bits wide,
00019  * because we don't want them ever to overflow.
00020  */
00021 typedef uint64 XLogRecPtr;
00022 
00023 /*
00024  * Zero is used indicate an invalid pointer. Bootstrap skips the first possible
00025  * WAL segment, initializing the first WAL page at XLOG_SEG_SIZE, so no XLOG
00026  * record can begin at zero.
00027  */
00028 #define InvalidXLogRecPtr   0
00029 #define XLogRecPtrIsInvalid(r)  ((r) == InvalidXLogRecPtr)
00030 
00031 /*
00032  * XLogSegNo - physical log file sequence number.
00033  */
00034 typedef uint64 XLogSegNo;
00035 
00036 /*
00037  * TimeLineID (TLI) - identifies different database histories to prevent
00038  * confusion after restoring a prior state of a database installation.
00039  * TLI does not change in a normal stop/restart of the database (including
00040  * crash-and-recover cases); but we must assign a new TLI after doing
00041  * a recovery to a prior state, a/k/a point-in-time recovery.  This makes
00042  * the new WAL logfile sequence we generate distinguishable from the
00043  * sequence that was generated in the previous incarnation.
00044  */
00045 typedef uint32 TimeLineID;
00046 
00047 /*
00048  *  Because O_DIRECT bypasses the kernel buffers, and because we never
00049  *  read those buffers except during crash recovery or if wal_level != minimal,
00050  *  it is a win to use it in all cases where we sync on each write().  We could
00051  *  allow O_DIRECT with fsync(), but it is unclear if fsync() could process
00052  *  writes not buffered in the kernel.  Also, O_DIRECT is never enough to force
00053  *  data to the drives, it merely tries to bypass the kernel cache, so we still
00054  *  need O_SYNC/O_DSYNC.
00055  */
00056 #ifdef O_DIRECT
00057 #define PG_O_DIRECT             O_DIRECT
00058 #else
00059 #define PG_O_DIRECT             0
00060 #endif
00061 
00062 /*
00063  * This chunk of hackery attempts to determine which file sync methods
00064  * are available on the current platform, and to choose an appropriate
00065  * default method.  We assume that fsync() is always available, and that
00066  * configure determined whether fdatasync() is.
00067  */
00068 #if defined(O_SYNC)
00069 #define OPEN_SYNC_FLAG      O_SYNC
00070 #elif defined(O_FSYNC)
00071 #define OPEN_SYNC_FLAG      O_FSYNC
00072 #endif
00073 
00074 #if defined(O_DSYNC)
00075 #if defined(OPEN_SYNC_FLAG)
00076 /* O_DSYNC is distinct? */
00077 #if O_DSYNC != OPEN_SYNC_FLAG
00078 #define OPEN_DATASYNC_FLAG      O_DSYNC
00079 #endif
00080 #else                           /* !defined(OPEN_SYNC_FLAG) */
00081 /* Win32 only has O_DSYNC */
00082 #define OPEN_DATASYNC_FLAG      O_DSYNC
00083 #endif
00084 #endif
00085 
00086 #if defined(PLATFORM_DEFAULT_SYNC_METHOD)
00087 #define DEFAULT_SYNC_METHOD     PLATFORM_DEFAULT_SYNC_METHOD
00088 #elif defined(OPEN_DATASYNC_FLAG)
00089 #define DEFAULT_SYNC_METHOD     SYNC_METHOD_OPEN_DSYNC
00090 #elif defined(HAVE_FDATASYNC)
00091 #define DEFAULT_SYNC_METHOD     SYNC_METHOD_FDATASYNC
00092 #else
00093 #define DEFAULT_SYNC_METHOD     SYNC_METHOD_FSYNC
00094 #endif
00095 
00096 /*
00097  * Limitation of buffer-alignment for direct IO depends on OS and filesystem,
00098  * but XLOG_BLCKSZ is assumed to be enough for it.
00099  */
00100 #ifdef O_DIRECT
00101 #define ALIGNOF_XLOG_BUFFER     XLOG_BLCKSZ
00102 #else
00103 #define ALIGNOF_XLOG_BUFFER     ALIGNOF_BUFFER
00104 #endif
00105 
00106 #endif   /* XLOG_DEFS_H */