]> granicus.if.org Git - postgresql/blob - src/include/catalog/pg_control.h
Replace XLogRecPtr struct with a 64-bit integer.
[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-2012, 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      931
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         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 */
45
46         /*
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.
51          */
52         TransactionId oldestActiveXid;
53 } CheckPoint;
54
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
65
66
67 /*
68  * System status indicator.  Note this is stored in pg_control; if you change
69  * it, you must bump PG_CONTROL_VERSION
70  */
71 typedef enum DBState
72 {
73         DB_STARTUP = 0,
74         DB_SHUTDOWNED,
75         DB_SHUTDOWNED_IN_RECOVERY,
76         DB_SHUTDOWNING,
77         DB_IN_CRASH_RECOVERY,
78         DB_IN_ARCHIVE_RECOVERY,
79         DB_IN_PRODUCTION
80 } DBState;
81
82 /*
83  * Contents of pg_control.
84  *
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.
88  */
89
90 typedef struct ControlFileData
91 {
92         /*
93          * Unique system identifier --- to ensure we match up xlog files with the
94          * installation that produced them.
95          */
96         uint64          system_identifier;
97
98         /*
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.)
103          *
104          * pg_control_version identifies the format of pg_control itself.
105          * catalog_version_no identifies the format of the system catalogs.
106          *
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.
110          */
111         uint32          pg_control_version;             /* PG_CONTROL_VERSION */
112         uint32          catalog_version_no;             /* see catversion.h */
113
114         /*
115          * System status data
116          */
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 */
121
122         CheckPoint      checkPointCopy; /* copy of last check point record */
123
124         /*
125          * These two values determine the minimum point we must recover up to
126          * before starting up:
127          *
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.
134          *
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.
142          *
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.
148          *
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().
154          */
155         XLogRecPtr      minRecoveryPoint;
156         XLogRecPtr      backupStartPoint;
157         XLogRecPtr      backupEndPoint;
158         bool            backupEndRequired;
159
160         /*
161          * Parameter settings that determine if the WAL can be used for archival
162          * or hot standby.
163          */
164         int                     wal_level;
165         int                     MaxConnections;
166         int                     max_prepared_xacts;
167         int                     max_locks_per_xact;
168
169         /*
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.)
177          *
178          * Testing just one double value is not a very bulletproof test for
179          * floating-point compatibility, but it will catch most cases.
180          */
181         uint32          maxAlign;               /* alignment requirement for tuples */
182         double          floatFormat;    /* constant 1234567.0 */
183 #define FLOATFORMAT_VALUE       1234567.0
184
185         /*
186          * This data is used to make sure that configuration of this database is
187          * compatible with the backend executable.
188          */
189         uint32          blcksz;                 /* data block size for this DB */
190         uint32          relseg_size;    /* blocks per segment of large relation */
191
192         uint32          xlog_blcksz;    /* block size within WAL files */
193         uint32          xlog_seg_size;  /* size of each WAL segment */
194
195         uint32          nameDataLen;    /* catalog name field width */
196         uint32          indexMaxKeys;   /* max number of columns in an index */
197
198         uint32          toast_max_chunk_size;   /* chunk size in TOAST tables */
199
200         /* flag indicating internal format of timestamp, interval, time */
201         bool            enableIntTimes; /* int64 storage enabled? */
202
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? */
206
207         /* CRC of all above ... MUST BE LAST! */
208         pg_crc32        crc;
209 } ControlFileData;
210
211 /*
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.
217  */
218 #define PG_CONTROL_SIZE         8192
219
220 #endif   /* PG_CONTROL_H */