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