1/*
2 * xlogdefs.h
3 *
4 * Postgres write-ahead log manager record pointer and
5 * timeline number definitions
6 *
7 * Portions Copyright (c) 1996-2019, 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 */
21typedef 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 * XLogSegNo - physical log file sequence number.
40 */
41typedef uint64 XLogSegNo;
42
43/*
44 * TimeLineID (TLI) - identifies different database histories to prevent
45 * confusion after restoring a prior state of a database installation.
46 * TLI does not change in a normal stop/restart of the database (including
47 * crash-and-recover cases); but we must assign a new TLI after doing
48 * a recovery to a prior state, a/k/a point-in-time recovery. This makes
49 * the new WAL logfile sequence we generate distinguishable from the
50 * sequence that was generated in the previous incarnation.
51 */
52typedef uint32 TimeLineID;
53
54/*
55 * Replication origin id - this is located in this file to avoid having to
56 * include origin.h in a bunch of xlog related places.
57 */
58typedef uint16 RepOriginId;
59
60/*
61 * Because O_DIRECT bypasses the kernel buffers, and because we never
62 * read those buffers except during crash recovery or if wal_level != minimal,
63 * it is a win to use it in all cases where we sync on each write(). We could
64 * allow O_DIRECT with fsync(), but it is unclear if fsync() could process
65 * writes not buffered in the kernel. Also, O_DIRECT is never enough to force
66 * data to the drives, it merely tries to bypass the kernel cache, so we still
67 * need O_SYNC/O_DSYNC.
68 */
69#ifdef O_DIRECT
70#define PG_O_DIRECT O_DIRECT
71#else
72#define PG_O_DIRECT 0
73#endif
74
75/*
76 * This chunk of hackery attempts to determine which file sync methods
77 * are available on the current platform, and to choose an appropriate
78 * default method. We assume that fsync() is always available, and that
79 * configure determined whether fdatasync() is.
80 */
81#if defined(O_SYNC)
82#define OPEN_SYNC_FLAG O_SYNC
83#elif defined(O_FSYNC)
84#define OPEN_SYNC_FLAG O_FSYNC
85#endif
86
87#if defined(O_DSYNC)
88#if defined(OPEN_SYNC_FLAG)
89/* O_DSYNC is distinct? */
90#if O_DSYNC != OPEN_SYNC_FLAG
91#define OPEN_DATASYNC_FLAG O_DSYNC
92#endif
93#else /* !defined(OPEN_SYNC_FLAG) */
94/* Win32 only has O_DSYNC */
95#define OPEN_DATASYNC_FLAG O_DSYNC
96#endif
97#endif
98
99#if defined(PLATFORM_DEFAULT_SYNC_METHOD)
100#define DEFAULT_SYNC_METHOD PLATFORM_DEFAULT_SYNC_METHOD
101#elif defined(OPEN_DATASYNC_FLAG)
102#define DEFAULT_SYNC_METHOD SYNC_METHOD_OPEN_DSYNC
103#elif defined(HAVE_FDATASYNC)
104#define DEFAULT_SYNC_METHOD SYNC_METHOD_FDATASYNC
105#else
106#define DEFAULT_SYNC_METHOD SYNC_METHOD_FSYNC
107#endif
108
109#endif /* XLOG_DEFS_H */
110