1 /*-------------------------------------------------------------------------
4 * The system control file "pg_control" is not a heap relation.
5 * However, we define it here so that the format is documented.
8 * Portions Copyright (c) 1996-2012, PostgreSQL Global Development Group
9 * Portions Copyright (c) 1994, Regents of the University of California
11 * src/include/catalog/pg_control.h
13 *-------------------------------------------------------------------------
18 #include "access/xlogdefs.h"
19 #include "pgtime.h" /* for pg_time_t */
20 #include "utils/pg_crc.h"
23 /* Version identifier for this pg_control format */
24 #define PG_CONTROL_VERSION 931
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.
31 typedef struct CheckPoint
33 XLogRecPtr redo; /* next RecPtr available when we began to
34 * create CheckPoint (i.e. REDO start point) */
35 TimeLineID ThisTimeLineID; /* current TLI */
36 bool fullPageWrites; /* current full_page_writes */
37 uint32 nextXidEpoch; /* higher-order bits of nextXid */
38 TransactionId nextXid; /* next free XID */
39 Oid nextOid; /* next free OID */
40 MultiXactId nextMulti; /* next free MultiXactId */
41 MultiXactOffset nextMultiOffset; /* next free MultiXact offset */
42 TransactionId oldestXid; /* cluster-wide minimum datfrozenxid */
43 Oid oldestXidDB; /* database with minimum datfrozenxid */
44 pg_time_t time; /* time stamp of checkpoint */
47 * Oldest XID still running. This is only needed to initialize hot standby
48 * mode from an online checkpoint, so we only bother calculating this for
49 * online checkpoints and only when wal_level is hot_standby. Otherwise
50 * it's set to InvalidTransactionId.
52 TransactionId oldestActiveXid;
55 /* XLOG info values for XLOG rmgr */
56 #define XLOG_CHECKPOINT_SHUTDOWN 0x00
57 #define XLOG_CHECKPOINT_ONLINE 0x10
58 #define XLOG_NOOP 0x20
59 #define XLOG_NEXTOID 0x30
60 #define XLOG_SWITCH 0x40
61 #define XLOG_BACKUP_END 0x50
62 #define XLOG_PARAMETER_CHANGE 0x60
63 #define XLOG_RESTORE_POINT 0x70
64 #define XLOG_FPW_CHANGE 0x80
68 * System status indicator. Note this is stored in pg_control; if you change
69 * it, you must bump PG_CONTROL_VERSION
75 DB_SHUTDOWNED_IN_RECOVERY,
78 DB_IN_ARCHIVE_RECOVERY,
83 * Contents of pg_control.
85 * NOTE: try to keep this under 512 bytes so that it will fit on one physical
86 * sector of typical disk drives. This reduces the odds of corruption due to
87 * power failure midway through a write.
90 typedef struct ControlFileData
93 * Unique system identifier --- to ensure we match up xlog files with the
94 * installation that produced them.
96 uint64 system_identifier;
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.)
104 * pg_control_version identifies the format of pg_control itself.
105 * catalog_version_no identifies the format of the system catalogs.
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.
111 uint32 pg_control_version; /* PG_CONTROL_VERSION */
112 uint32 catalog_version_no; /* see catversion.h */
117 DBState state; /* see enum above */
118 pg_time_t time; /* time stamp of last pg_control update */
119 XLogRecPtr checkPoint; /* last check point record ptr */
120 XLogRecPtr prevCheckPoint; /* previous check point record ptr */
122 CheckPoint checkPointCopy; /* copy of last check point record */
125 * These two values determine the minimum point we must recover up to
126 * before starting up:
128 * minRecoveryPoint is updated to the latest replayed LSN whenever we
129 * flush a data change during archive recovery. That guards against
130 * starting archive recovery, aborting it, and restarting with an earlier
131 * stop location. If we've already flushed data changes from WAL record X
132 * to disk, we mustn't start up until we reach X again. Zero when not
133 * doing archive recovery.
135 * backupStartPoint is the redo pointer of the backup start checkpoint, if
136 * we are recovering from an online backup and haven't reached the end of
137 * backup yet. It is reset to zero when the end of backup is reached, and
138 * we mustn't start up before that. A boolean would suffice otherwise, but
139 * we use the redo pointer as a cross-check when we see an end-of-backup
140 * record, to make sure the end-of-backup record corresponds the base
141 * backup we're recovering from.
143 * backupEndPoint is the backup end location, if we are recovering from an
144 * online backup which was taken from the standby and haven't reached the
145 * end of backup yet. It is initialized to the minimum recovery point in
146 * pg_control which was backed up last. It is reset to zero when the end
147 * of backup is reached, and we mustn't start up before that.
149 * If backupEndRequired is true, we know for sure that we're restoring
150 * from a backup, and must see a backup-end record before we can safely
151 * start up. If it's false, but backupStartPoint is set, a backup_label
152 * file was found at startup but it may have been a leftover from a stray
153 * pg_start_backup() call, not accompanied by pg_stop_backup().
155 XLogRecPtr minRecoveryPoint;
156 XLogRecPtr backupStartPoint;
157 XLogRecPtr backupEndPoint;
158 bool backupEndRequired;
161 * Parameter settings that determine if the WAL can be used for archival
166 int max_prepared_xacts;
167 int max_locks_per_xact;
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.)
178 * Testing just one double value is not a very bulletproof test for
179 * floating-point compatibility, but it will catch most cases.
181 uint32 maxAlign; /* alignment requirement for tuples */
182 double floatFormat; /* constant 1234567.0 */
183 #define FLOATFORMAT_VALUE 1234567.0
186 * This data is used to make sure that configuration of this database is
187 * compatible with the backend executable.
189 uint32 blcksz; /* data block size for this DB */
190 uint32 relseg_size; /* blocks per segment of large relation */
192 uint32 xlog_blcksz; /* block size within WAL files */
193 uint32 xlog_seg_size; /* size of each WAL segment */
195 uint32 nameDataLen; /* catalog name field width */
196 uint32 indexMaxKeys; /* max number of columns in an index */
198 uint32 toast_max_chunk_size; /* chunk size in TOAST tables */
200 /* flag indicating internal format of timestamp, interval, time */
201 bool enableIntTimes; /* int64 storage enabled? */
203 /* flags indicating pass-by-value status of various types */
204 bool float4ByVal; /* float4 pass-by-value? */
205 bool float8ByVal; /* float8, int8, etc pass-by-value? */
207 /* CRC of all above ... MUST BE LAST! */
212 * Physical size of the pg_control file. Note that this is considerably
213 * bigger than the actually used size (ie, sizeof(ControlFileData)).
214 * The idea is to keep the physical size constant independent of format
215 * changes, so that ReadControlFile will deliver a suitable wrong-version
216 * message instead of a read error if it's looking at an incompatible file.
218 #define PG_CONTROL_SIZE 8192
220 #endif /* PG_CONTROL_H */