4 * Postgres transaction log manager record pointer and
5 * timeline number definitions
7 * Portions Copyright (c) 1996-2010, 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.24 2010/01/02 16:58:01 momjian Exp $
15 #include <fcntl.h> /* need open() flags */
18 * Pointer to a location in the XLOG. These pointers are 64 bits wide,
19 * because we don't want them ever to overflow.
21 * NOTE: xrecoff == 0 is used to indicate an invalid pointer. This is OK
22 * because we use page headers in the XLOG, so no XLOG record can start
23 * right at the beginning of a file.
25 * NOTE: the "log file number" is somewhat misnamed, since the actual files
26 * making up the XLOG are much smaller than 4Gb. Each actual file is an
27 * XLogSegSize-byte "segment" of a logical log file having the indicated
28 * xlogid. The log file number and segment number together identify a
29 * physical XLOG file. Segment number and offset within the physical file
30 * are computed from xrecoff div and mod XLogSegSize.
32 typedef struct XLogRecPtr
34 uint32 xlogid; /* log file #, 0 based */
35 uint32 xrecoff; /* byte offset of location in log file */
38 #define XLogRecPtrIsInvalid(r) ((r).xrecoff == 0)
42 * Macros for comparing XLogRecPtrs
44 * Beware of passing expressions with side-effects to these macros,
45 * since the arguments may be evaluated multiple times.
47 #define XLByteLT(a, b) \
48 ((a).xlogid < (b).xlogid || \
49 ((a).xlogid == (b).xlogid && (a).xrecoff < (b).xrecoff))
51 #define XLByteLE(a, b) \
52 ((a).xlogid < (b).xlogid || \
53 ((a).xlogid == (b).xlogid && (a).xrecoff <= (b).xrecoff))
55 #define XLByteEQ(a, b) \
56 ((a).xlogid == (b).xlogid && (a).xrecoff == (b).xrecoff)
60 * TimeLineID (TLI) - identifies different database histories to prevent
61 * confusion after restoring a prior state of a database installation.
62 * TLI does not change in a normal stop/restart of the database (including
63 * crash-and-recover cases); but we must assign a new TLI after doing
64 * a recovery to a prior state, a/k/a point-in-time recovery. This makes
65 * the new WAL logfile sequence we generate distinguishable from the
66 * sequence that was generated in the previous incarnation.
68 typedef uint32 TimeLineID;
71 * Because O_DIRECT bypasses the kernel buffers, and because we never
72 * read those buffers except during crash recovery, it is a win to use
73 * it in all cases where we sync on each write(). We could allow O_DIRECT
74 * with fsync(), but because skipping the kernel buffer forces writes out
75 * quickly, it seems best just to use it for O_SYNC. It is hard to imagine
76 * how fsync() could be a win for O_DIRECT compared to O_SYNC and O_DIRECT.
77 * Also, O_DIRECT is never enough to force data to the drives, it merely
78 * tries to bypass the kernel cache, so we still need O_SYNC or fsync().
81 #define PG_O_DIRECT O_DIRECT
87 * This chunk of hackery attempts to determine which file sync methods
88 * are available on the current platform, and to choose an appropriate
89 * default method. We assume that fsync() is always available, and that
90 * configure determined whether fdatasync() is.
93 #define BARE_OPEN_SYNC_FLAG O_SYNC
94 #elif defined(O_FSYNC)
95 #define BARE_OPEN_SYNC_FLAG O_FSYNC
97 #ifdef BARE_OPEN_SYNC_FLAG
98 #define OPEN_SYNC_FLAG (BARE_OPEN_SYNC_FLAG | PG_O_DIRECT)
102 #if defined(OPEN_SYNC_FLAG)
103 /* O_DSYNC is distinct? */
104 #if O_DSYNC != BARE_OPEN_SYNC_FLAG
105 #define OPEN_DATASYNC_FLAG (O_DSYNC | PG_O_DIRECT)
107 #else /* !defined(OPEN_SYNC_FLAG) */
108 /* Win32 only has O_DSYNC */
109 #define OPEN_DATASYNC_FLAG (O_DSYNC | PG_O_DIRECT)
113 #if defined(OPEN_DATASYNC_FLAG)
114 #define DEFAULT_SYNC_METHOD SYNC_METHOD_OPEN_DSYNC
115 #elif defined(HAVE_FDATASYNC)
116 #define DEFAULT_SYNC_METHOD SYNC_METHOD_FDATASYNC
117 #elif defined(HAVE_FSYNC_WRITETHROUGH_ONLY)
118 #define DEFAULT_SYNC_METHOD SYNC_METHOD_FSYNC_WRITETHROUGH
120 #define DEFAULT_SYNC_METHOD SYNC_METHOD_FSYNC
124 * Limitation of buffer-alignment for direct IO depends on OS and filesystem,
125 * but XLOG_BLCKSZ is assumed to be enough for it.
128 #define ALIGNOF_XLOG_BUFFER XLOG_BLCKSZ
130 #define ALIGNOF_XLOG_BUFFER ALIGNOF_BUFFER
133 #endif /* XLOG_DEFS_H */