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-2011, 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 911
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 uint32 nextXidEpoch; /* higher-order bits of nextXid */
37 TransactionId nextXid; /* next free XID */
38 Oid nextOid; /* next free OID */
39 MultiXactId nextMulti; /* next free MultiXactId */
40 MultiXactOffset nextMultiOffset; /* next free MultiXact offset */
41 TransactionId oldestXid; /* cluster-wide minimum datfrozenxid */
42 Oid oldestXidDB; /* database with minimum datfrozenxid */
43 pg_time_t time; /* time stamp of checkpoint */
46 * Oldest XID still running. This is only needed to initialize hot standby
47 * mode from an online checkpoint, so we only bother calculating this for
48 * online checkpoints and only when wal_level is hot_standby. Otherwise
49 * it's set to InvalidTransactionId.
51 TransactionId oldestActiveXid;
54 /* XLOG info values for XLOG rmgr */
55 #define XLOG_CHECKPOINT_SHUTDOWN 0x00
56 #define XLOG_CHECKPOINT_ONLINE 0x10
57 #define XLOG_NOOP 0x20
58 #define XLOG_NEXTOID 0x30
59 #define XLOG_SWITCH 0x40
60 #define XLOG_BACKUP_END 0x50
61 #define XLOG_PARAMETER_CHANGE 0x60
62 #define XLOG_RESTORE_POINT 0x70
66 * System status indicator. Note this is stored in pg_control; if you change
67 * it, you must bump PG_CONTROL_VERSION
73 DB_SHUTDOWNED_IN_RECOVERY,
76 DB_IN_ARCHIVE_RECOVERY,
81 * Contents of pg_control.
83 * NOTE: try to keep this under 512 bytes so that it will fit on one physical
84 * sector of typical disk drives. This reduces the odds of corruption due to
85 * power failure midway through a write.
88 typedef struct ControlFileData
91 * Unique system identifier --- to ensure we match up xlog files with the
92 * installation that produced them.
94 uint64 system_identifier;
97 * Version identifier information. Keep these fields at the same offset,
98 * especially pg_control_version; they won't be real useful if they move
99 * around. (For historical reasons they must be 8 bytes into the file
100 * rather than immediately at the front.)
102 * pg_control_version identifies the format of pg_control itself.
103 * catalog_version_no identifies the format of the system catalogs.
105 * There are additional version identifiers in individual files; for
106 * example, WAL logs contain per-page magic numbers that can serve as
107 * version cues for the WAL log.
109 uint32 pg_control_version; /* PG_CONTROL_VERSION */
110 uint32 catalog_version_no; /* see catversion.h */
115 DBState state; /* see enum above */
116 pg_time_t time; /* time stamp of last pg_control update */
117 XLogRecPtr checkPoint; /* last check point record ptr */
118 XLogRecPtr prevCheckPoint; /* previous check point record ptr */
120 CheckPoint checkPointCopy; /* copy of last check point record */
123 * These two values determine the minimum point we must recover up to
124 * before starting up:
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.
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.
141 * If backupEndRequired is true, we know for sure that we're restoring
142 * from a backup, and must see a backup-end record before we can safely
143 * start up. If it's false, but backupStartPoint is set, a backup_label
144 * file was found at startup but it may have been a leftover from a stray
145 * pg_start_backup() call, not accompanied by pg_stop_backup().
147 XLogRecPtr minRecoveryPoint;
148 XLogRecPtr backupStartPoint;
149 bool backupEndRequired;
152 * Parameter settings that determine if the WAL can be used for archival
157 int max_prepared_xacts;
158 int max_locks_per_xact;
161 * This data is used to check for hardware-architecture compatibility of
162 * the database and the backend executable. We need not check endianness
163 * explicitly, since the pg_control version will surely look wrong to a
164 * machine of different endianness, but we do need to worry about MAXALIGN
165 * and floating-point format. (Note: storage layout nominally also
166 * depends on SHORTALIGN and INTALIGN, but in practice these are the same
167 * on all architectures of interest.)
169 * Testing just one double value is not a very bulletproof test for
170 * floating-point compatibility, but it will catch most cases.
172 uint32 maxAlign; /* alignment requirement for tuples */
173 double floatFormat; /* constant 1234567.0 */
174 #define FLOATFORMAT_VALUE 1234567.0
177 * This data is used to make sure that configuration of this database is
178 * compatible with the backend executable.
180 uint32 blcksz; /* data block size for this DB */
181 uint32 relseg_size; /* blocks per segment of large relation */
183 uint32 xlog_blcksz; /* block size within WAL files */
184 uint32 xlog_seg_size; /* size of each WAL segment */
186 uint32 nameDataLen; /* catalog name field width */
187 uint32 indexMaxKeys; /* max number of columns in an index */
189 uint32 toast_max_chunk_size; /* chunk size in TOAST tables */
191 /* flag indicating internal format of timestamp, interval, time */
192 bool enableIntTimes; /* int64 storage enabled? */
194 /* flags indicating pass-by-value status of various types */
195 bool float4ByVal; /* float4 pass-by-value? */
196 bool float8ByVal; /* float8, int8, etc pass-by-value? */
198 /* CRC of all above ... MUST BE LAST! */
203 * Physical size of the pg_control file. Note that this is considerably
204 * bigger than the actually used size (ie, sizeof(ControlFileData)).
205 * The idea is to keep the physical size constant independent of format
206 * changes, so that ReadControlFile will deliver a suitable wrong-version
207 * message instead of a read error if it's looking at an incompatible file.
209 #define PG_CONTROL_SIZE 8192
211 #endif /* PG_CONTROL_H */