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