]> granicus.if.org Git - postgresql/blob - src/include/catalog/pg_control.h
Named restore points in recovery. Users can record named points, then
[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-2011, 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      903
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         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 */
44
45         /*
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 it's
49          * set to InvalidTransactionId.
50          */
51         TransactionId oldestActiveXid;
52 } CheckPoint;
53
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
63
64
65 /*
66  * System status indicator.  Note this is stored in pg_control; if you change
67  * it, you must bump PG_CONTROL_VERSION
68  */
69 typedef enum DBState
70 {
71         DB_STARTUP = 0,
72         DB_SHUTDOWNED,
73         DB_SHUTDOWNED_IN_RECOVERY,
74         DB_SHUTDOWNING,
75         DB_IN_CRASH_RECOVERY,
76         DB_IN_ARCHIVE_RECOVERY,
77         DB_IN_PRODUCTION
78 } DBState;
79
80 /*
81  * Contents of pg_control.
82  *
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.
86  */
87
88 typedef struct ControlFileData
89 {
90         /*
91          * Unique system identifier --- to ensure we match up xlog files with the
92          * installation that produced them.
93          */
94         uint64          system_identifier;
95
96         /*
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.)
101          *
102          * pg_control_version identifies the format of pg_control itself.
103          * catalog_version_no identifies the format of the system catalogs.
104          *
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.
108          */
109         uint32          pg_control_version;             /* PG_CONTROL_VERSION */
110         uint32          catalog_version_no;             /* see catversion.h */
111
112         /*
113          * System status data
114          */
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 */
119
120         CheckPoint      checkPointCopy; /* copy of last check point record */
121
122         /*
123          * These two values determine the minimum point we must recover up to
124          * before starting up:
125          *
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.
132          *
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.
140          */
141         XLogRecPtr      minRecoveryPoint;
142         XLogRecPtr      backupStartPoint;
143
144         /*
145          * Parameter settings that determine if the WAL can be used for archival
146          * or hot standby.
147          */
148         int                     wal_level;
149         int                     MaxConnections;
150         int                     max_prepared_xacts;
151         int                     max_locks_per_xact;
152
153         /*
154          * This data is used to check for hardware-architecture compatibility of
155          * the database and the backend executable.  We need not check endianness
156          * explicitly, since the pg_control version will surely look wrong to a
157          * machine of different endianness, but we do need to worry about MAXALIGN
158          * and floating-point format.  (Note: storage layout nominally also
159          * depends on SHORTALIGN and INTALIGN, but in practice these are the same
160          * on all architectures of interest.)
161          *
162          * Testing just one double value is not a very bulletproof test for
163          * floating-point compatibility, but it will catch most cases.
164          */
165         uint32          maxAlign;               /* alignment requirement for tuples */
166         double          floatFormat;    /* constant 1234567.0 */
167 #define FLOATFORMAT_VALUE       1234567.0
168
169         /*
170          * This data is used to make sure that configuration of this database is
171          * compatible with the backend executable.
172          */
173         uint32          blcksz;                 /* data block size for this DB */
174         uint32          relseg_size;    /* blocks per segment of large relation */
175
176         uint32          xlog_blcksz;    /* block size within WAL files */
177         uint32          xlog_seg_size;  /* size of each WAL segment */
178
179         uint32          nameDataLen;    /* catalog name field width */
180         uint32          indexMaxKeys;   /* max number of columns in an index */
181
182         uint32          toast_max_chunk_size;   /* chunk size in TOAST tables */
183
184         /* flag indicating internal format of timestamp, interval, time */
185         bool            enableIntTimes; /* int64 storage enabled? */
186
187         /* flags indicating pass-by-value status of various types */
188         bool            float4ByVal;    /* float4 pass-by-value? */
189         bool            float8ByVal;    /* float8, int8, etc pass-by-value? */
190
191         /* CRC of all above ... MUST BE LAST! */
192         pg_crc32        crc;
193 } ControlFileData;
194
195 /*
196  * Physical size of the pg_control file.  Note that this is considerably
197  * bigger than the actually used size (ie, sizeof(ControlFileData)).
198  * The idea is to keep the physical size constant independent of format
199  * changes, so that ReadControlFile will deliver a suitable wrong-version
200  * message instead of a read error if it's looking at an incompatible file.
201  */
202 #define PG_CONTROL_SIZE         8192
203
204 #endif   /* PG_CONTROL_H */