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-2024, 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.
71  *
72  * Note that we define our own O_DSYNC on Windows, but not O_SYNC.
73  */
74 #if defined(PLATFORM_DEFAULT_WAL_SYNC_METHOD)
75 #define DEFAULT_WAL_SYNC_METHOD PLATFORM_DEFAULT_WAL_SYNC_METHOD
76 #elif defined(O_DSYNC) && (!defined(O_SYNC) || O_DSYNC != O_SYNC)
77 #define DEFAULT_WAL_SYNC_METHOD WAL_SYNC_METHOD_OPEN_DSYNC
78 #else
79 #define DEFAULT_WAL_SYNC_METHOD WAL_SYNC_METHOD_FDATASYNC
80 #endif
81 
82 #endif /* XLOG_DEFS_H */
unsigned short uint16
Definition: c.h:492
unsigned int uint32
Definition: c.h:493
uint16 RepOriginId
Definition: xlogdefs.h:65
uint64 XLogRecPtr
Definition: xlogdefs.h:21
uint32 TimeLineID
Definition: xlogdefs.h:59
uint64 XLogSegNo
Definition: xlogdefs.h:48