xlogdefs.h 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  1. /*
  2. * xlogdefs.h
  3. *
  4. * Postgres write-ahead log manager record pointer and
  5. * timeline number definitions
  6. *
  7. * Portions Copyright (c) 1996-2022, 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. #include <fcntl.h> /* need open() flags */
  15. /*
  16. * Pointer to a location in the XLOG. These pointers are 64 bits wide,
  17. * because we don't want them ever to overflow.
  18. */
  19. typedef uint64 XLogRecPtr;
  20. /*
  21. * Zero is used indicate an invalid pointer. Bootstrap skips the first possible
  22. * WAL segment, initializing the first WAL page at WAL segment size, so no XLOG
  23. * record can begin at zero.
  24. */
  25. #define InvalidXLogRecPtr 0
  26. #define XLogRecPtrIsInvalid(r) ((r) == InvalidXLogRecPtr)
  27. /*
  28. * First LSN to use for "fake" LSNs.
  29. *
  30. * Values smaller than this can be used for special per-AM purposes.
  31. */
  32. #define FirstNormalUnloggedLSN ((XLogRecPtr) 1000)
  33. /*
  34. * Handy macro for printing XLogRecPtr in conventional format, e.g.,
  35. *
  36. * printf("%X/%X", LSN_FORMAT_ARGS(lsn));
  37. */
  38. #define LSN_FORMAT_ARGS(lsn) (AssertVariableIsOfTypeMacro((lsn), XLogRecPtr), (uint32) ((lsn) >> 32)), ((uint32) (lsn))
  39. /*
  40. * XLogSegNo - physical log file sequence number.
  41. */
  42. typedef uint64 XLogSegNo;
  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. */
  52. typedef uint32 TimeLineID;
  53. /*
  54. * Replication origin id - this is located in this file to avoid having to
  55. * include origin.h in a bunch of xlog related places.
  56. */
  57. typedef uint16 RepOriginId;
  58. /*
  59. * This chunk of hackery attempts to determine which file sync methods
  60. * are available on the current platform, and to choose an appropriate
  61. * default method. We assume that fsync() is always available, and that
  62. * configure determined whether fdatasync() is.
  63. */
  64. #if defined(O_SYNC)
  65. #define OPEN_SYNC_FLAG O_SYNC
  66. #elif defined(O_FSYNC)
  67. #define OPEN_SYNC_FLAG O_FSYNC
  68. #endif
  69. #if defined(O_DSYNC)
  70. #if defined(OPEN_SYNC_FLAG)
  71. /* O_DSYNC is distinct? */
  72. #if O_DSYNC != OPEN_SYNC_FLAG
  73. #define OPEN_DATASYNC_FLAG O_DSYNC
  74. #endif
  75. #else /* !defined(OPEN_SYNC_FLAG) */
  76. /* Win32 only has O_DSYNC */
  77. #define OPEN_DATASYNC_FLAG O_DSYNC
  78. #endif
  79. #endif
  80. #if defined(PLATFORM_DEFAULT_SYNC_METHOD)
  81. #define DEFAULT_SYNC_METHOD PLATFORM_DEFAULT_SYNC_METHOD
  82. #elif defined(OPEN_DATASYNC_FLAG)
  83. #define DEFAULT_SYNC_METHOD SYNC_METHOD_OPEN_DSYNC
  84. #elif defined(HAVE_FDATASYNC)
  85. #define DEFAULT_SYNC_METHOD SYNC_METHOD_FDATASYNC
  86. #else
  87. #define DEFAULT_SYNC_METHOD SYNC_METHOD_FSYNC
  88. #endif
  89. #endif /* XLOG_DEFS_H */