pg_control.h 8.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241
  1. /*-------------------------------------------------------------------------
  2. *
  3. * pg_control.h
  4. * The system control file "pg_control" is not a heap relation.
  5. * However, we define it here so that the format is documented.
  6. *
  7. *
  8. * Portions Copyright (c) 1996-2016, PostgreSQL Global Development Group
  9. * Portions Copyright (c) 1994, Regents of the University of California
  10. *
  11. * src/include/catalog/pg_control.h
  12. *
  13. *-------------------------------------------------------------------------
  14. */
  15. #ifndef PG_CONTROL_H
  16. #define PG_CONTROL_H
  17. #include "access/xlogdefs.h"
  18. #include "pgtime.h" /* for pg_time_t */
  19. #include "port/pg_crc32c.h"
  20. /* Version identifier for this pg_control format */
  21. #define PG_CONTROL_VERSION 960
  22. /*
  23. * Body of CheckPoint XLOG records. This is declared here because we keep
  24. * a copy of the latest one in pg_control for possible disaster recovery.
  25. * Changing this struct requires a PG_CONTROL_VERSION bump.
  26. */
  27. typedef struct CheckPoint
  28. {
  29. XLogRecPtr redo; /* next RecPtr available when we began to
  30. * create CheckPoint (i.e. REDO start point) */
  31. TimeLineID ThisTimeLineID; /* current TLI */
  32. TimeLineID PrevTimeLineID; /* previous TLI, if this record begins a new
  33. * timeline (equals ThisTimeLineID otherwise) */
  34. bool fullPageWrites; /* current full_page_writes */
  35. uint32 nextXidEpoch; /* higher-order bits of nextXid */
  36. TransactionId nextXid; /* next free XID */
  37. Oid nextOid; /* next free OID */
  38. MultiXactId nextMulti; /* next free MultiXactId */
  39. MultiXactOffset nextMultiOffset; /* next free MultiXact offset */
  40. TransactionId oldestXid; /* cluster-wide minimum datfrozenxid */
  41. Oid oldestXidDB; /* database with minimum datfrozenxid */
  42. MultiXactId oldestMulti; /* cluster-wide minimum datminmxid */
  43. Oid oldestMultiDB; /* database with minimum datminmxid */
  44. pg_time_t time; /* time stamp of checkpoint */
  45. TransactionId oldestCommitTsXid; /* oldest Xid with valid commit
  46. * timestamp */
  47. TransactionId newestCommitTsXid; /* newest Xid with valid commit
  48. * timestamp */
  49. /*
  50. * Oldest XID still running. This is only needed to initialize hot standby
  51. * mode from an online checkpoint, so we only bother calculating this for
  52. * online checkpoints and only when wal_level is replica. Otherwise it's
  53. * set to InvalidTransactionId.
  54. */
  55. TransactionId oldestActiveXid;
  56. } CheckPoint;
  57. /* XLOG info values for XLOG rmgr */
  58. #define XLOG_CHECKPOINT_SHUTDOWN 0x00
  59. #define XLOG_CHECKPOINT_ONLINE 0x10
  60. #define XLOG_NOOP 0x20
  61. #define XLOG_NEXTOID 0x30
  62. #define XLOG_SWITCH 0x40
  63. #define XLOG_BACKUP_END 0x50
  64. #define XLOG_PARAMETER_CHANGE 0x60
  65. #define XLOG_RESTORE_POINT 0x70
  66. #define XLOG_FPW_CHANGE 0x80
  67. #define XLOG_END_OF_RECOVERY 0x90
  68. #define XLOG_FPI_FOR_HINT 0xA0
  69. #define XLOG_FPI 0xB0
  70. /*
  71. * System status indicator. Note this is stored in pg_control; if you change
  72. * it, you must bump PG_CONTROL_VERSION
  73. */
  74. typedef enum DBState
  75. {
  76. DB_STARTUP = 0,
  77. DB_SHUTDOWNED,
  78. DB_SHUTDOWNED_IN_RECOVERY,
  79. DB_SHUTDOWNING,
  80. DB_IN_CRASH_RECOVERY,
  81. DB_IN_ARCHIVE_RECOVERY,
  82. DB_IN_PRODUCTION
  83. } DBState;
  84. /*
  85. * Contents of pg_control.
  86. *
  87. * NOTE: try to keep this under 512 bytes so that it will fit on one physical
  88. * sector of typical disk drives. This reduces the odds of corruption due to
  89. * power failure midway through a write.
  90. */
  91. typedef struct ControlFileData
  92. {
  93. /*
  94. * Unique system identifier --- to ensure we match up xlog files with the
  95. * installation that produced them.
  96. */
  97. uint64 system_identifier;
  98. /*
  99. * Version identifier information. Keep these fields at the same offset,
  100. * especially pg_control_version; they won't be real useful if they move
  101. * around. (For historical reasons they must be 8 bytes into the file
  102. * rather than immediately at the front.)
  103. *
  104. * pg_control_version identifies the format of pg_control itself.
  105. * catalog_version_no identifies the format of the system catalogs.
  106. *
  107. * There are additional version identifiers in individual files; for
  108. * example, WAL logs contain per-page magic numbers that can serve as
  109. * version cues for the WAL log.
  110. */
  111. uint32 pg_control_version; /* PG_CONTROL_VERSION */
  112. uint32 catalog_version_no; /* see catversion.h */
  113. /*
  114. * System status data
  115. */
  116. DBState state; /* see enum above */
  117. pg_time_t time; /* time stamp of last pg_control update */
  118. XLogRecPtr checkPoint; /* last check point record ptr */
  119. XLogRecPtr prevCheckPoint; /* previous check point record ptr */
  120. CheckPoint checkPointCopy; /* copy of last check point record */
  121. XLogRecPtr unloggedLSN; /* current fake LSN value, for unlogged rels */
  122. /*
  123. * These two values determine the minimum point we must recover up to
  124. * before starting up:
  125. *
  126. * minRecoveryPoint is updated to the latest replayed LSN whenever we
  127. * flush a data change during archive recovery. That guards against
  128. * starting archive recovery, aborting it, and restarting with an earlier
  129. * stop location. If we've already flushed data changes from WAL record X
  130. * to disk, we mustn't start up until we reach X again. Zero when not
  131. * doing archive recovery.
  132. *
  133. * backupStartPoint is the redo pointer of the backup start checkpoint, if
  134. * we are recovering from an online backup and haven't reached the end of
  135. * backup yet. It is reset to zero when the end of backup is reached, and
  136. * we mustn't start up before that. A boolean would suffice otherwise, but
  137. * we use the redo pointer as a cross-check when we see an end-of-backup
  138. * record, to make sure the end-of-backup record corresponds the base
  139. * backup we're recovering from.
  140. *
  141. * backupEndPoint is the backup end location, if we are recovering from an
  142. * online backup which was taken from the standby and haven't reached the
  143. * end of backup yet. It is initialized to the minimum recovery point in
  144. * pg_control which was backed up last. It is reset to zero when the end
  145. * of backup is reached, and we mustn't start up before that.
  146. *
  147. * If backupEndRequired is true, we know for sure that we're restoring
  148. * from a backup, and must see a backup-end record before we can safely
  149. * start up. If it's false, but backupStartPoint is set, a backup_label
  150. * file was found at startup but it may have been a leftover from a stray
  151. * pg_start_backup() call, not accompanied by pg_stop_backup().
  152. */
  153. XLogRecPtr minRecoveryPoint;
  154. TimeLineID minRecoveryPointTLI;
  155. XLogRecPtr backupStartPoint;
  156. XLogRecPtr backupEndPoint;
  157. bool backupEndRequired;
  158. /*
  159. * Parameter settings that determine if the WAL can be used for archival
  160. * or hot standby.
  161. */
  162. int wal_level;
  163. bool wal_log_hints;
  164. int MaxConnections;
  165. int max_worker_processes;
  166. int max_prepared_xacts;
  167. int max_locks_per_xact;
  168. bool track_commit_timestamp;
  169. /*
  170. * This data is used to check for hardware-architecture compatibility of
  171. * the database and the backend executable. We need not check endianness
  172. * explicitly, since the pg_control version will surely look wrong to a
  173. * machine of different endianness, but we do need to worry about MAXALIGN
  174. * and floating-point format. (Note: storage layout nominally also
  175. * depends on SHORTALIGN and INTALIGN, but in practice these are the same
  176. * on all architectures of interest.)
  177. *
  178. * Testing just one double value is not a very bulletproof test for
  179. * floating-point compatibility, but it will catch most cases.
  180. */
  181. uint32 maxAlign; /* alignment requirement for tuples */
  182. double floatFormat; /* constant 1234567.0 */
  183. #define FLOATFORMAT_VALUE 1234567.0
  184. /*
  185. * This data is used to make sure that configuration of this database is
  186. * compatible with the backend executable.
  187. */
  188. uint32 blcksz; /* data block size for this DB */
  189. uint32 relseg_size; /* blocks per segment of large relation */
  190. uint32 xlog_blcksz; /* block size within WAL files */
  191. uint32 xlog_seg_size; /* size of each WAL segment */
  192. uint32 nameDataLen; /* catalog name field width */
  193. uint32 indexMaxKeys; /* max number of columns in an index */
  194. uint32 toast_max_chunk_size; /* chunk size in TOAST tables */
  195. uint32 loblksize; /* chunk size in pg_largeobject */
  196. /* flag indicating internal format of timestamp, interval, time */
  197. bool enableIntTimes; /* int64 storage enabled? */
  198. /* flags indicating pass-by-value status of various types */
  199. bool float4ByVal; /* float4 pass-by-value? */
  200. bool float8ByVal; /* float8, int8, etc pass-by-value? */
  201. /* Are data pages protected by checksums? Zero if no checksum version */
  202. uint32 data_checksum_version;
  203. /* CRC of all above ... MUST BE LAST! */
  204. pg_crc32c crc;
  205. } ControlFileData;
  206. /*
  207. * Physical size of the pg_control file. Note that this is considerably
  208. * bigger than the actually used size (ie, sizeof(ControlFileData)).
  209. * The idea is to keep the physical size constant independent of format
  210. * changes, so that ReadControlFile will deliver a suitable wrong-version
  211. * message instead of a read error if it's looking at an incompatible file.
  212. */
  213. #define PG_CONTROL_SIZE 8192
  214. #endif /* PG_CONTROL_H */