PostgreSQL Source Code  git master
xlogdefs.h
Go to the documentation of this file.
1 /*
2  * xlogdefs.h
3  *
4  * Postgres write-ahead log manager record pointer and
5  * timeline number definitions
6  *
7  * Portions Copyright (c) 1996-2021, PostgreSQL Global Development Group
8  * Portions Copyright (c) 1994, Regents of the University of California
9  *
10  * src/include/access/xlogdefs.h
11  */
12 #ifndef XLOG_DEFS_H
13 #define XLOG_DEFS_H
14 
15 #include <fcntl.h> /* need open() flags */
16 
17 /*
18  * Pointer to a location in the XLOG. These pointers are 64 bits wide,
19  * because we don't want them ever to overflow.
20  */
21 typedef uint64 XLogRecPtr;
22 
23 /*
24  * Zero is used indicate an invalid pointer. Bootstrap skips the first possible
25  * WAL segment, initializing the first WAL page at WAL segment size, so no XLOG
26  * record can begin at zero.
27  */
28 #define InvalidXLogRecPtr 0
29 #define XLogRecPtrIsInvalid(r) ((r) == InvalidXLogRecPtr)
30 
31 /*
32  * First LSN to use for "fake" LSNs.
33  *
34  * Values smaller than this can be used for special per-AM purposes.
35  */
36 #define FirstNormalUnloggedLSN ((XLogRecPtr) 1000)
37 
38 /*
39  * Handy macro for printing XLogRecPtr in conventional format, e.g.,
40  *
41  * printf("%X/%X", LSN_FORMAT_ARGS(lsn));
42  */
43 #define LSN_FORMAT_ARGS(lsn) (AssertVariableIsOfTypeMacro((lsn), XLogRecPtr), (uint32) ((lsn) >> 32)), ((uint32) (lsn))
44 
45 /*
46  * XLogSegNo - physical log file sequence number.
47  */
48 typedef uint64 XLogSegNo;
49 
50 /*
51  * TimeLineID (TLI) - identifies different database histories to prevent
52  * confusion after restoring a prior state of a database installation.
53  * TLI does not change in a normal stop/restart of the database (including
54  * crash-and-recover cases); but we must assign a new TLI after doing
55  * a recovery to a prior state, a/k/a point-in-time recovery. This makes
56  * the new WAL logfile sequence we generate distinguishable from the
57  * sequence that was generated in the previous incarnation.
58  */
60 
61 /*
62  * Replication origin id - this is located in this file to avoid having to
63  * include origin.h in a bunch of xlog related places.
64  */
66 
67 /*
68  * Because O_DIRECT bypasses the kernel buffers, and because we never
69  * read those buffers except during crash recovery or if wal_level != minimal,
70  * it is a win to use it in all cases where we sync on each write(). We could
71  * allow O_DIRECT with fsync(), but it is unclear if fsync() could process
72  * writes not buffered in the kernel. Also, O_DIRECT is never enough to force
73  * data to the drives, it merely tries to bypass the kernel cache, so we still
74  * need O_SYNC/O_DSYNC.
75  */
76 #ifdef O_DIRECT
77 #define PG_O_DIRECT O_DIRECT
78 #else
79 #define PG_O_DIRECT 0
80 #endif
81 
82 /*
83  * This chunk of hackery attempts to determine which file sync methods
84  * are available on the current platform, and to choose an appropriate
85  * default method. We assume that fsync() is always available, and that
86  * configure determined whether fdatasync() is.
87  */
88 #if defined(O_SYNC)
89 #define OPEN_SYNC_FLAG O_SYNC
90 #elif defined(O_FSYNC)
91 #define OPEN_SYNC_FLAG O_FSYNC
92 #endif
93 
94 #if defined(O_DSYNC)
95 #if defined(OPEN_SYNC_FLAG)
96 /* O_DSYNC is distinct? */
97 #if O_DSYNC != OPEN_SYNC_FLAG
98 #define OPEN_DATASYNC_FLAG O_DSYNC
99 #endif
100 #else /* !defined(OPEN_SYNC_FLAG) */
101 /* Win32 only has O_DSYNC */
102 #define OPEN_DATASYNC_FLAG O_DSYNC
103 #endif
104 #endif
105 
106 #if defined(PLATFORM_DEFAULT_SYNC_METHOD)
107 #define DEFAULT_SYNC_METHOD PLATFORM_DEFAULT_SYNC_METHOD
108 #elif defined(OPEN_DATASYNC_FLAG)
109 #define DEFAULT_SYNC_METHOD SYNC_METHOD_OPEN_DSYNC
110 #elif defined(HAVE_FDATASYNC)
111 #define DEFAULT_SYNC_METHOD SYNC_METHOD_FDATASYNC
112 #else
113 #define DEFAULT_SYNC_METHOD SYNC_METHOD_FSYNC
114 #endif
115 
116 #endif /* XLOG_DEFS_H */
uint32 TimeLineID
Definition: xlogdefs.h:59
uint16 RepOriginId
Definition: xlogdefs.h:65
unsigned short uint16
Definition: c.h:440
uint64 XLogSegNo
Definition: xlogdefs.h:48
unsigned int uint32
Definition: c.h:441
uint64 XLogRecPtr
Definition: xlogdefs.h:21