]> granicus.if.org Git - postgresql/blob - src/include/catalog/pg_control.h
Record data_checksum_version in control file.
[postgresql] / src / include / catalog / pg_control.h
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-2013, 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 "utils/pg_crc.h"
21
22
23 /* Version identifier for this pg_control format */
24 #define PG_CONTROL_VERSION      936
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
50         /*
51          * Oldest XID still running. This is only needed to initialize hot standby
52          * mode from an online checkpoint, so we only bother calculating this for
53          * online checkpoints and only when wal_level is hot_standby. Otherwise
54          * it's set to InvalidTransactionId.
55          */
56         TransactionId oldestActiveXid;
57 } CheckPoint;
58
59 /* XLOG info values for XLOG rmgr */
60 #define XLOG_CHECKPOINT_SHUTDOWN                0x00
61 #define XLOG_CHECKPOINT_ONLINE                  0x10
62 #define XLOG_NOOP                                               0x20
63 #define XLOG_NEXTOID                                    0x30
64 #define XLOG_SWITCH                                             0x40
65 #define XLOG_BACKUP_END                                 0x50
66 #define XLOG_PARAMETER_CHANGE                   0x60
67 #define XLOG_RESTORE_POINT                              0x70
68 #define XLOG_FPW_CHANGE                                 0x80
69 #define XLOG_END_OF_RECOVERY                    0x90
70 #define XLOG_HINT                                               0xA0
71
72
73 /*
74  * System status indicator.  Note this is stored in pg_control; if you change
75  * it, you must bump PG_CONTROL_VERSION
76  */
77 typedef enum DBState
78 {
79         DB_STARTUP = 0,
80         DB_SHUTDOWNED,
81         DB_SHUTDOWNED_IN_RECOVERY,
82         DB_SHUTDOWNING,
83         DB_IN_CRASH_RECOVERY,
84         DB_IN_ARCHIVE_RECOVERY,
85         DB_IN_PRODUCTION
86 } DBState;
87
88 /*
89  * Contents of pg_control.
90  *
91  * NOTE: try to keep this under 512 bytes so that it will fit on one physical
92  * sector of typical disk drives.  This reduces the odds of corruption due to
93  * power failure midway through a write.
94  */
95
96 typedef struct ControlFileData
97 {
98         /*
99          * Unique system identifier --- to ensure we match up xlog files with the
100          * installation that produced them.
101          */
102         uint64          system_identifier;
103
104         /*
105          * Version identifier information.      Keep these fields at the same offset,
106          * especially pg_control_version; they won't be real useful if they move
107          * around.      (For historical reasons they must be 8 bytes into the file
108          * rather than immediately at the front.)
109          *
110          * pg_control_version identifies the format of pg_control itself.
111          * catalog_version_no identifies the format of the system catalogs.
112          *
113          * There are additional version identifiers in individual files; for
114          * example, WAL logs contain per-page magic numbers that can serve as
115          * version cues for the WAL log.
116          */
117         uint32          pg_control_version;             /* PG_CONTROL_VERSION */
118         uint32          catalog_version_no;             /* see catversion.h */
119
120         /*
121          * System status data
122          */
123         DBState         state;                  /* see enum above */
124         pg_time_t       time;                   /* time stamp of last pg_control update */
125         XLogRecPtr      checkPoint;             /* last check point record ptr */
126         XLogRecPtr      prevCheckPoint; /* previous check point record ptr */
127
128         CheckPoint      checkPointCopy; /* copy of last check point record */
129
130         XLogRecPtr  unloggedLSN;        /* current fake LSN value, for unlogged rels */
131
132         /*
133          * These two values determine the minimum point we must recover up to
134          * before starting up:
135          *
136          * minRecoveryPoint is updated to the latest replayed LSN whenever we
137          * flush a data change during archive recovery. That guards against
138          * starting archive recovery, aborting it, and restarting with an earlier
139          * stop location. If we've already flushed data changes from WAL record X
140          * to disk, we mustn't start up until we reach X again. Zero when not
141          * doing archive recovery.
142          *
143          * backupStartPoint is the redo pointer of the backup start checkpoint, if
144          * we are recovering from an online backup and haven't reached the end of
145          * backup yet. It is reset to zero when the end of backup is reached, and
146          * we mustn't start up before that. A boolean would suffice otherwise, but
147          * we use the redo pointer as a cross-check when we see an end-of-backup
148          * record, to make sure the end-of-backup record corresponds the base
149          * backup we're recovering from.
150          *
151          * backupEndPoint is the backup end location, if we are recovering from an
152          * online backup which was taken from the standby and haven't reached the
153          * end of backup yet. It is initialized to the minimum recovery point in
154          * pg_control which was backed up last. It is reset to zero when the end
155          * of backup is reached, and we mustn't start up before that.
156          *
157          * If backupEndRequired is true, we know for sure that we're restoring
158          * from a backup, and must see a backup-end record before we can safely
159          * start up. If it's false, but backupStartPoint is set, a backup_label
160          * file was found at startup but it may have been a leftover from a stray
161          * pg_start_backup() call, not accompanied by pg_stop_backup().
162          */
163         XLogRecPtr      minRecoveryPoint;
164         TimeLineID      minRecoveryPointTLI;
165         XLogRecPtr      backupStartPoint;
166         XLogRecPtr      backupEndPoint;
167         bool            backupEndRequired;
168
169         /*
170          * Parameter settings that determine if the WAL can be used for archival
171          * or hot standby.
172          */
173         int                     wal_level;
174         int                     MaxConnections;
175         int                     max_prepared_xacts;
176         int                     max_locks_per_xact;
177
178         /*
179          * This data is used to check for hardware-architecture compatibility of
180          * the database and the backend executable.  We need not check endianness
181          * explicitly, since the pg_control version will surely look wrong to a
182          * machine of different endianness, but we do need to worry about MAXALIGN
183          * and floating-point format.  (Note: storage layout nominally also
184          * depends on SHORTALIGN and INTALIGN, but in practice these are the same
185          * on all architectures of interest.)
186          *
187          * Testing just one double value is not a very bulletproof test for
188          * floating-point compatibility, but it will catch most cases.
189          */
190         uint32          maxAlign;               /* alignment requirement for tuples */
191         double          floatFormat;    /* constant 1234567.0 */
192 #define FLOATFORMAT_VALUE       1234567.0
193
194         /*
195          * This data is used to make sure that configuration of this database is
196          * compatible with the backend executable.
197          */
198         uint32          blcksz;                 /* data block size for this DB */
199         uint32          relseg_size;    /* blocks per segment of large relation */
200
201         uint32          xlog_blcksz;    /* block size within WAL files */
202         uint32          xlog_seg_size;  /* size of each WAL segment */
203
204         uint32          nameDataLen;    /* catalog name field width */
205         uint32          indexMaxKeys;   /* max number of columns in an index */
206
207         uint32          toast_max_chunk_size;   /* chunk size in TOAST tables */
208
209         /* flag indicating internal format of timestamp, interval, time */
210         bool            enableIntTimes; /* int64 storage enabled? */
211
212         /* flags indicating pass-by-value status of various types */
213         bool            float4ByVal;    /* float4 pass-by-value? */
214         bool            float8ByVal;    /* float8, int8, etc pass-by-value? */
215
216         /* Are data pages protected by checksums? Zero if no checksum version */
217         uint32          data_checksum_version;
218
219         /* CRC of all above ... MUST BE LAST! */
220         pg_crc32        crc;
221 } ControlFileData;
222
223 /*
224  * Physical size of the pg_control file.  Note that this is considerably
225  * bigger than the actually used size (ie, sizeof(ControlFileData)).
226  * The idea is to keep the physical size constant independent of format
227  * changes, so that ReadControlFile will deliver a suitable wrong-version
228  * message instead of a read error if it's looking at an incompatible file.
229  */
230 #define PG_CONTROL_SIZE         8192
231
232 #endif   /* PG_CONTROL_H */