]> granicus.if.org Git - postgresql/blob - src/include/access/xlogdefs.h
Introduce replication progress tracking infrastructure.
[postgresql] / src / include / access / xlogdefs.h
1 /*
2  * xlogdefs.h
3  *
4  * Postgres transaction log manager record pointer and
5  * timeline number definitions
6  *
7  * Portions Copyright (c) 1996-2015, 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 XLOG_SEG_SIZE, so no XLOG
26  * record can begin at zero.
27  */
28 #define InvalidXLogRecPtr       0
29 #define XLogRecPtrIsInvalid(r)  ((r) == InvalidXLogRecPtr)
30
31 /*
32  * XLogSegNo - physical log file sequence number.
33  */
34 typedef uint64 XLogSegNo;
35
36 /*
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.
44  */
45 typedef uint32 TimeLineID;
46
47 /*
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.
50  */
51 typedef uint16 RepOriginId;
52
53 /*
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.
61  */
62 #ifdef O_DIRECT
63 #define PG_O_DIRECT                             O_DIRECT
64 #else
65 #define PG_O_DIRECT                             0
66 #endif
67
68 /*
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.
73  */
74 #if defined(O_SYNC)
75 #define OPEN_SYNC_FLAG          O_SYNC
76 #elif defined(O_FSYNC)
77 #define OPEN_SYNC_FLAG          O_FSYNC
78 #endif
79
80 #if defined(O_DSYNC)
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
85 #endif
86 #else                                                   /* !defined(OPEN_SYNC_FLAG) */
87 /* Win32 only has O_DSYNC */
88 #define OPEN_DATASYNC_FLAG              O_DSYNC
89 #endif
90 #endif
91
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
98 #else
99 #define DEFAULT_SYNC_METHOD             SYNC_METHOD_FSYNC
100 #endif
101
102 #endif   /* XLOG_DEFS_H */