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  * This chunk of hackery attempts to determine which file sync methods
69  * are available on the current platform, and to choose an appropriate
70  * default method. We assume that fsync() is always available, and that
71  * configure determined whether fdatasync() is.
72  */
73 #if defined(O_SYNC)
74 #define OPEN_SYNC_FLAG O_SYNC
75 #elif defined(O_FSYNC)
76 #define OPEN_SYNC_FLAG O_FSYNC
77 #endif
78 
79 #if defined(O_DSYNC)
80 #if defined(OPEN_SYNC_FLAG)
81 /* O_DSYNC is distinct? */
82 #if O_DSYNC != OPEN_SYNC_FLAG
83 #define OPEN_DATASYNC_FLAG O_DSYNC
84 #endif
85 #else /* !defined(OPEN_SYNC_FLAG) */
86 /* Win32 only has O_DSYNC */
87 #define OPEN_DATASYNC_FLAG O_DSYNC
88 #endif
89 #endif
90 
91 #if defined(PLATFORM_DEFAULT_SYNC_METHOD)
92 #define DEFAULT_SYNC_METHOD PLATFORM_DEFAULT_SYNC_METHOD
93 #elif defined(OPEN_DATASYNC_FLAG)
94 #define DEFAULT_SYNC_METHOD SYNC_METHOD_OPEN_DSYNC
95 #elif defined(HAVE_FDATASYNC)
96 #define DEFAULT_SYNC_METHOD SYNC_METHOD_FDATASYNC
97 #else
98 #define DEFAULT_SYNC_METHOD SYNC_METHOD_FSYNC
99 #endif
100 
101 #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