00001 /*------------------------------------------------------------------------- 00002 * 00003 * pg_control.h 00004 * The system control file "pg_control" is not a heap relation. 00005 * However, we define it here so that the format is documented. 00006 * 00007 * 00008 * Portions Copyright (c) 1996-2013, PostgreSQL Global Development Group 00009 * Portions Copyright (c) 1994, Regents of the University of California 00010 * 00011 * src/include/catalog/pg_control.h 00012 * 00013 *------------------------------------------------------------------------- 00014 */ 00015 #ifndef PG_CONTROL_H 00016 #define PG_CONTROL_H 00017 00018 #include "access/xlogdefs.h" 00019 #include "pgtime.h" /* for pg_time_t */ 00020 #include "utils/pg_crc.h" 00021 00022 00023 /* Version identifier for this pg_control format */ 00024 #define PG_CONTROL_VERSION 937 00025 00026 /* 00027 * Body of CheckPoint XLOG records. This is declared here because we keep 00028 * a copy of the latest one in pg_control for possible disaster recovery. 00029 * Changing this struct requires a PG_CONTROL_VERSION bump. 00030 */ 00031 typedef struct CheckPoint 00032 { 00033 XLogRecPtr redo; /* next RecPtr available when we began to 00034 * create CheckPoint (i.e. REDO start point) */ 00035 TimeLineID ThisTimeLineID; /* current TLI */ 00036 TimeLineID PrevTimeLineID; /* previous TLI, if this record begins a new 00037 * timeline (equals ThisTimeLineID otherwise) */ 00038 bool fullPageWrites; /* current full_page_writes */ 00039 uint32 nextXidEpoch; /* higher-order bits of nextXid */ 00040 TransactionId nextXid; /* next free XID */ 00041 Oid nextOid; /* next free OID */ 00042 MultiXactId nextMulti; /* next free MultiXactId */ 00043 MultiXactOffset nextMultiOffset; /* next free MultiXact offset */ 00044 TransactionId oldestXid; /* cluster-wide minimum datfrozenxid */ 00045 Oid oldestXidDB; /* database with minimum datfrozenxid */ 00046 MultiXactId oldestMulti; /* cluster-wide minimum datminmxid */ 00047 Oid oldestMultiDB; /* database with minimum datminmxid */ 00048 pg_time_t time; /* time stamp of checkpoint */ 00049 00050 /* 00051 * Oldest XID still running. This is only needed to initialize hot standby 00052 * mode from an online checkpoint, so we only bother calculating this for 00053 * online checkpoints and only when wal_level is hot_standby. Otherwise 00054 * it's set to InvalidTransactionId. 00055 */ 00056 TransactionId oldestActiveXid; 00057 } CheckPoint; 00058 00059 /* XLOG info values for XLOG rmgr */ 00060 #define XLOG_CHECKPOINT_SHUTDOWN 0x00 00061 #define XLOG_CHECKPOINT_ONLINE 0x10 00062 #define XLOG_NOOP 0x20 00063 #define XLOG_NEXTOID 0x30 00064 #define XLOG_SWITCH 0x40 00065 #define XLOG_BACKUP_END 0x50 00066 #define XLOG_PARAMETER_CHANGE 0x60 00067 #define XLOG_RESTORE_POINT 0x70 00068 #define XLOG_FPW_CHANGE 0x80 00069 #define XLOG_END_OF_RECOVERY 0x90 00070 #define XLOG_HINT 0xA0 00071 00072 00073 /* 00074 * System status indicator. Note this is stored in pg_control; if you change 00075 * it, you must bump PG_CONTROL_VERSION 00076 */ 00077 typedef enum DBState 00078 { 00079 DB_STARTUP = 0, 00080 DB_SHUTDOWNED, 00081 DB_SHUTDOWNED_IN_RECOVERY, 00082 DB_SHUTDOWNING, 00083 DB_IN_CRASH_RECOVERY, 00084 DB_IN_ARCHIVE_RECOVERY, 00085 DB_IN_PRODUCTION 00086 } DBState; 00087 00088 /* 00089 * Contents of pg_control. 00090 * 00091 * NOTE: try to keep this under 512 bytes so that it will fit on one physical 00092 * sector of typical disk drives. This reduces the odds of corruption due to 00093 * power failure midway through a write. 00094 */ 00095 00096 typedef struct ControlFileData 00097 { 00098 /* 00099 * Unique system identifier --- to ensure we match up xlog files with the 00100 * installation that produced them. 00101 */ 00102 uint64 system_identifier; 00103 00104 /* 00105 * Version identifier information. Keep these fields at the same offset, 00106 * especially pg_control_version; they won't be real useful if they move 00107 * around. (For historical reasons they must be 8 bytes into the file 00108 * rather than immediately at the front.) 00109 * 00110 * pg_control_version identifies the format of pg_control itself. 00111 * catalog_version_no identifies the format of the system catalogs. 00112 * 00113 * There are additional version identifiers in individual files; for 00114 * example, WAL logs contain per-page magic numbers that can serve as 00115 * version cues for the WAL log. 00116 */ 00117 uint32 pg_control_version; /* PG_CONTROL_VERSION */ 00118 uint32 catalog_version_no; /* see catversion.h */ 00119 00120 /* 00121 * System status data 00122 */ 00123 DBState state; /* see enum above */ 00124 pg_time_t time; /* time stamp of last pg_control update */ 00125 XLogRecPtr checkPoint; /* last check point record ptr */ 00126 XLogRecPtr prevCheckPoint; /* previous check point record ptr */ 00127 00128 CheckPoint checkPointCopy; /* copy of last check point record */ 00129 00130 XLogRecPtr unloggedLSN; /* current fake LSN value, for unlogged rels */ 00131 00132 /* 00133 * These two values determine the minimum point we must recover up to 00134 * before starting up: 00135 * 00136 * minRecoveryPoint is updated to the latest replayed LSN whenever we 00137 * flush a data change during archive recovery. That guards against 00138 * starting archive recovery, aborting it, and restarting with an earlier 00139 * stop location. If we've already flushed data changes from WAL record X 00140 * to disk, we mustn't start up until we reach X again. Zero when not 00141 * doing archive recovery. 00142 * 00143 * backupStartPoint is the redo pointer of the backup start checkpoint, if 00144 * we are recovering from an online backup and haven't reached the end of 00145 * backup yet. It is reset to zero when the end of backup is reached, and 00146 * we mustn't start up before that. A boolean would suffice otherwise, but 00147 * we use the redo pointer as a cross-check when we see an end-of-backup 00148 * record, to make sure the end-of-backup record corresponds the base 00149 * backup we're recovering from. 00150 * 00151 * backupEndPoint is the backup end location, if we are recovering from an 00152 * online backup which was taken from the standby and haven't reached the 00153 * end of backup yet. It is initialized to the minimum recovery point in 00154 * pg_control which was backed up last. It is reset to zero when the end 00155 * of backup is reached, and we mustn't start up before that. 00156 * 00157 * If backupEndRequired is true, we know for sure that we're restoring 00158 * from a backup, and must see a backup-end record before we can safely 00159 * start up. If it's false, but backupStartPoint is set, a backup_label 00160 * file was found at startup but it may have been a leftover from a stray 00161 * pg_start_backup() call, not accompanied by pg_stop_backup(). 00162 */ 00163 XLogRecPtr minRecoveryPoint; 00164 TimeLineID minRecoveryPointTLI; 00165 XLogRecPtr backupStartPoint; 00166 XLogRecPtr backupEndPoint; 00167 bool backupEndRequired; 00168 00169 /* 00170 * Parameter settings that determine if the WAL can be used for archival 00171 * or hot standby. 00172 */ 00173 int wal_level; 00174 int MaxConnections; 00175 int max_prepared_xacts; 00176 int max_locks_per_xact; 00177 00178 /* 00179 * This data is used to check for hardware-architecture compatibility of 00180 * the database and the backend executable. We need not check endianness 00181 * explicitly, since the pg_control version will surely look wrong to a 00182 * machine of different endianness, but we do need to worry about MAXALIGN 00183 * and floating-point format. (Note: storage layout nominally also 00184 * depends on SHORTALIGN and INTALIGN, but in practice these are the same 00185 * on all architectures of interest.) 00186 * 00187 * Testing just one double value is not a very bulletproof test for 00188 * floating-point compatibility, but it will catch most cases. 00189 */ 00190 uint32 maxAlign; /* alignment requirement for tuples */ 00191 double floatFormat; /* constant 1234567.0 */ 00192 #define FLOATFORMAT_VALUE 1234567.0 00193 00194 /* 00195 * This data is used to make sure that configuration of this database is 00196 * compatible with the backend executable. 00197 */ 00198 uint32 blcksz; /* data block size for this DB */ 00199 uint32 relseg_size; /* blocks per segment of large relation */ 00200 00201 uint32 xlog_blcksz; /* block size within WAL files */ 00202 uint32 xlog_seg_size; /* size of each WAL segment */ 00203 00204 uint32 nameDataLen; /* catalog name field width */ 00205 uint32 indexMaxKeys; /* max number of columns in an index */ 00206 00207 uint32 toast_max_chunk_size; /* chunk size in TOAST tables */ 00208 00209 /* flag indicating internal format of timestamp, interval, time */ 00210 bool enableIntTimes; /* int64 storage enabled? */ 00211 00212 /* flags indicating pass-by-value status of various types */ 00213 bool float4ByVal; /* float4 pass-by-value? */ 00214 bool float8ByVal; /* float8, int8, etc pass-by-value? */ 00215 00216 /* Are data pages protected by checksums? Zero if no checksum version */ 00217 uint32 data_checksum_version; 00218 00219 /* CRC of all above ... MUST BE LAST! */ 00220 pg_crc32 crc; 00221 } ControlFileData; 00222 00223 /* 00224 * Physical size of the pg_control file. Note that this is considerably 00225 * bigger than the actually used size (ie, sizeof(ControlFileData)). 00226 * The idea is to keep the physical size constant independent of format 00227 * changes, so that ReadControlFile will deliver a suitable wrong-version 00228 * message instead of a read error if it's looking at an incompatible file. 00229 */ 00230 #define PG_CONTROL_SIZE 8192 00231 00232 #endif /* PG_CONTROL_H */