4 * Postgres transaction log manager record pointer and
5 * timeline number definitions
7 * Portions Copyright (c) 1996-2015, PostgreSQL Global Development Group
8 * Portions Copyright (c) 1994, Regents of the University of California
10 * src/include/access/xlogdefs.h
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 typedef uint64 XLogRecPtr;
24 * Zero is used indicate an invalid pointer. Bootstrap skips the first possible
25 * WAL segment, initializing the first WAL page at XLOG_SEG_SIZE, so no XLOG
26 * record can begin at zero.
28 #define InvalidXLogRecPtr 0
29 #define XLogRecPtrIsInvalid(r) ((r) == InvalidXLogRecPtr)
32 * XLogSegNo - physical log file sequence number.
34 typedef uint64 XLogSegNo;
37 * TimeLineID (TLI) - identifies different database histories to prevent
38 * confusion after restoring a prior state of a database installation.
39 * TLI does not change in a normal stop/restart of the database (including
40 * crash-and-recover cases); but we must assign a new TLI after doing
41 * a recovery to a prior state, a/k/a point-in-time recovery. This makes
42 * the new WAL logfile sequence we generate distinguishable from the
43 * sequence that was generated in the previous incarnation.
45 typedef uint32 TimeLineID;
48 * Replication origin id - this is located in this file to avoid having to
49 * include origin.h in a bunch of xlog related places.
51 typedef uint16 RepOriginId;
54 * Because O_DIRECT bypasses the kernel buffers, and because we never
55 * read those buffers except during crash recovery or if wal_level != minimal,
56 * it is a win to use it in all cases where we sync on each write(). We could
57 * allow O_DIRECT with fsync(), but it is unclear if fsync() could process
58 * writes not buffered in the kernel. Also, O_DIRECT is never enough to force
59 * data to the drives, it merely tries to bypass the kernel cache, so we still
60 * need O_SYNC/O_DSYNC.
63 #define PG_O_DIRECT O_DIRECT
69 * This chunk of hackery attempts to determine which file sync methods
70 * are available on the current platform, and to choose an appropriate
71 * default method. We assume that fsync() is always available, and that
72 * configure determined whether fdatasync() is.
75 #define OPEN_SYNC_FLAG O_SYNC
76 #elif defined(O_FSYNC)
77 #define OPEN_SYNC_FLAG O_FSYNC
81 #if defined(OPEN_SYNC_FLAG)
82 /* O_DSYNC is distinct? */
83 #if O_DSYNC != OPEN_SYNC_FLAG
84 #define OPEN_DATASYNC_FLAG O_DSYNC
86 #else /* !defined(OPEN_SYNC_FLAG) */
87 /* Win32 only has O_DSYNC */
88 #define OPEN_DATASYNC_FLAG O_DSYNC
92 #if defined(PLATFORM_DEFAULT_SYNC_METHOD)
93 #define DEFAULT_SYNC_METHOD PLATFORM_DEFAULT_SYNC_METHOD
94 #elif defined(OPEN_DATASYNC_FLAG)
95 #define DEFAULT_SYNC_METHOD SYNC_METHOD_OPEN_DSYNC
96 #elif defined(HAVE_FDATASYNC)
97 #define DEFAULT_SYNC_METHOD SYNC_METHOD_FDATASYNC
99 #define DEFAULT_SYNC_METHOD SYNC_METHOD_FSYNC
102 #endif /* XLOG_DEFS_H */