4 * Postgres transaction log manager record pointer and
5 * timeline number definitions
7 * Portions Copyright (c) 1996-2008, PostgreSQL Global Development Group
8 * Portions Copyright (c) 1994, Regents of the University of California
10 * $PostgreSQL: pgsql/src/include/access/xlogdefs.h,v 1.19 2008/01/01 19:45:56 momjian Exp $
16 * Pointer to a location in the XLOG. These pointers are 64 bits wide,
17 * because we don't want them ever to overflow.
19 * NOTE: xrecoff == 0 is used to indicate an invalid pointer. This is OK
20 * because we use page headers in the XLOG, so no XLOG record can start
21 * right at the beginning of a file.
23 * NOTE: the "log file number" is somewhat misnamed, since the actual files
24 * making up the XLOG are much smaller than 4Gb. Each actual file is an
25 * XLogSegSize-byte "segment" of a logical log file having the indicated
26 * xlogid. The log file number and segment number together identify a
27 * physical XLOG file. Segment number and offset within the physical file
28 * are computed from xrecoff div and mod XLogSegSize.
30 typedef struct XLogRecPtr
32 uint32 xlogid; /* log file #, 0 based */
33 uint32 xrecoff; /* byte offset of location in log file */
36 #define XLogRecPtrIsInvalid(r) ((r).xrecoff == 0)
40 * Macros for comparing XLogRecPtrs
42 * Beware of passing expressions with side-effects to these macros,
43 * since the arguments may be evaluated multiple times.
45 #define XLByteLT(a, b) \
46 ((a).xlogid < (b).xlogid || \
47 ((a).xlogid == (b).xlogid && (a).xrecoff < (b).xrecoff))
49 #define XLByteLE(a, b) \
50 ((a).xlogid < (b).xlogid || \
51 ((a).xlogid == (b).xlogid && (a).xrecoff <= (b).xrecoff))
53 #define XLByteEQ(a, b) \
54 ((a).xlogid == (b).xlogid && (a).xrecoff == (b).xrecoff)
58 * TimeLineID (TLI) - identifies different database histories to prevent
59 * confusion after restoring a prior state of a database installation.
60 * TLI does not change in a normal stop/restart of the database (including
61 * crash-and-recover cases); but we must assign a new TLI after doing
62 * a recovery to a prior state, a/k/a point-in-time recovery. This makes
63 * the new WAL logfile sequence we generate distinguishable from the
64 * sequence that was generated in the previous incarnation.
66 typedef uint32 TimeLineID;
69 * Because O_DIRECT bypasses the kernel buffers, and because we never
70 * read those buffers except during crash recovery, it is a win to use
71 * it in all cases where we sync on each write(). We could allow O_DIRECT
72 * with fsync(), but because skipping the kernel buffer forces writes out
73 * quickly, it seems best just to use it for O_SYNC. It is hard to imagine
74 * how fsync() could be a win for O_DIRECT compared to O_SYNC and O_DIRECT.
75 * Also, O_DIRECT is never enough to force data to the drives, it merely
76 * tries to bypass the kernel cache, so we still need O_SYNC or fsync().
79 #define PG_O_DIRECT O_DIRECT
85 * This chunk of hackery attempts to determine which file sync methods
86 * are available on the current platform, and to choose an appropriate
87 * default method. We assume that fsync() is always available, and that
88 * configure determined whether fdatasync() is.
91 #define BARE_OPEN_SYNC_FLAG O_SYNC
92 #elif defined(O_FSYNC)
93 #define BARE_OPEN_SYNC_FLAG O_FSYNC
95 #ifdef BARE_OPEN_SYNC_FLAG
96 #define OPEN_SYNC_FLAG (BARE_OPEN_SYNC_FLAG | PG_O_DIRECT)
100 #if defined(OPEN_SYNC_FLAG)
101 /* O_DSYNC is distinct? */
102 #if O_DSYNC != BARE_OPEN_SYNC_FLAG
103 #define OPEN_DATASYNC_FLAG (O_DSYNC | PG_O_DIRECT)
105 #else /* !defined(OPEN_SYNC_FLAG) */
106 /* Win32 only has O_DSYNC */
107 #define OPEN_DATASYNC_FLAG (O_DSYNC | PG_O_DIRECT)
111 #if defined(OPEN_DATASYNC_FLAG)
112 #define DEFAULT_SYNC_METHOD_STR "open_datasync"
113 #define DEFAULT_SYNC_METHOD SYNC_METHOD_OPEN
114 #define DEFAULT_SYNC_FLAGBIT OPEN_DATASYNC_FLAG
115 #elif defined(HAVE_FDATASYNC)
116 #define DEFAULT_SYNC_METHOD_STR "fdatasync"
117 #define DEFAULT_SYNC_METHOD SYNC_METHOD_FDATASYNC
118 #define DEFAULT_SYNC_FLAGBIT 0
119 #elif defined(HAVE_FSYNC_WRITETHROUGH_ONLY)
120 #define DEFAULT_SYNC_METHOD_STR "fsync_writethrough"
121 #define DEFAULT_SYNC_METHOD SYNC_METHOD_FSYNC_WRITETHROUGH
122 #define DEFAULT_SYNC_FLAGBIT 0
124 #define DEFAULT_SYNC_METHOD_STR "fsync"
125 #define DEFAULT_SYNC_METHOD SYNC_METHOD_FSYNC
126 #define DEFAULT_SYNC_FLAGBIT 0
130 * Limitation of buffer-alignment for direct IO depends on OS and filesystem,
131 * but XLOG_BLCKSZ is assumed to be enough for it.
134 #define ALIGNOF_XLOG_BUFFER XLOG_BLCKSZ
136 #define ALIGNOF_XLOG_BUFFER ALIGNOF_BUFFER
139 #endif /* XLOG_DEFS_H */