PostgreSQL Source Code git master
Loading...
Searching...
No Matches
pg_control.h
Go to the documentation of this file.
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-2026, 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/transam.h"
19#include "access/xlogdefs.h"
20#include "pgtime.h" /* for pg_time_t */
21#include "port/pg_crc32c.h"
22
23
24/* Version identifier for this pg_control format */
25#define PG_CONTROL_VERSION 1902
26
27/* Nonce key length, see below */
28#define MOCK_AUTH_NONCE_LEN 32
29
30/*
31 * Body of CheckPoint XLOG records. This is declared here because we keep
32 * a copy of the latest one in pg_control for possible disaster recovery.
33 * Changing this struct requires a PG_CONTROL_VERSION bump.
34 */
35typedef struct CheckPoint
36{
37 XLogRecPtr redo; /* next RecPtr available when we began to
38 * create CheckPoint (i.e. REDO start point) */
39 TimeLineID ThisTimeLineID; /* current TLI */
40 TimeLineID PrevTimeLineID; /* previous TLI, if this record begins a new
41 * timeline (equals ThisTimeLineID otherwise) */
42 bool fullPageWrites; /* current full_page_writes */
43 int wal_level; /* current wal_level */
44 bool logicalDecodingEnabled; /* current logical decoding status */
45 FullTransactionId nextXid; /* next free transaction ID */
46 Oid nextOid; /* next free OID */
47 MultiXactId nextMulti; /* next free MultiXactId */
48 MultiXactOffset nextMultiOffset; /* next free MultiXact offset */
49 TransactionId oldestXid; /* cluster-wide minimum datfrozenxid */
50 Oid oldestXidDB; /* database with minimum datfrozenxid */
51 MultiXactId oldestMulti; /* cluster-wide minimum datminmxid */
52 Oid oldestMultiDB; /* database with minimum datminmxid */
53 pg_time_t time; /* time stamp of checkpoint */
54 TransactionId oldestCommitTsXid; /* oldest Xid with valid commit
55 * timestamp */
56 TransactionId newestCommitTsXid; /* newest Xid with valid commit
57 * timestamp */
58
59 /*
60 * Oldest XID still running. This is only needed to initialize hot standby
61 * mode from an online checkpoint, so we only bother calculating this for
62 * online checkpoints and only when wal_level is replica. Otherwise it's
63 * set to InvalidTransactionId.
64 */
66
67 /* data checksums state at the time of the checkpoint */
70
71/* XLOG info values for XLOG rmgr */
72#define XLOG_CHECKPOINT_SHUTDOWN 0x00
73#define XLOG_CHECKPOINT_ONLINE 0x10
74#define XLOG_NOOP 0x20
75#define XLOG_NEXTOID 0x30
76#define XLOG_SWITCH 0x40
77#define XLOG_BACKUP_END 0x50
78#define XLOG_PARAMETER_CHANGE 0x60
79#define XLOG_RESTORE_POINT 0x70
80#define XLOG_FPW_CHANGE 0x80
81#define XLOG_END_OF_RECOVERY 0x90
82#define XLOG_FPI_FOR_HINT 0xA0
83#define XLOG_FPI 0xB0
84#define XLOG_ASSIGN_LSN 0xC0
85#define XLOG_OVERWRITE_CONTRECORD 0xD0
86#define XLOG_CHECKPOINT_REDO 0xE0
87#define XLOG_LOGICAL_DECODING_STATUS_CHANGE 0xF0
88
89/* XLOG info values for XLOG2 rmgr */
90#define XLOG2_CHECKSUMS 0x00
91
92
93/*
94 * System status indicator. Note this is stored in pg_control; if you change
95 * it, you must bump PG_CONTROL_VERSION
96 */
107
108/*
109 * Contents of pg_control.
110 */
111
112typedef struct ControlFileData
113{
114 /*
115 * Unique system identifier --- to ensure we match up xlog files with the
116 * installation that produced them.
117 */
119
120 /*
121 * Version identifier information. Keep these fields at the same offset,
122 * especially pg_control_version; they won't be real useful if they move
123 * around. (For historical reasons they must be 8 bytes into the file
124 * rather than immediately at the front.)
125 *
126 * pg_control_version identifies the format of pg_control itself.
127 * catalog_version_no identifies the format of the system catalogs.
128 *
129 * There are additional version identifiers in individual files; for
130 * example, WAL logs contain per-page magic numbers that can serve as
131 * version cues for the WAL log.
132 */
133 uint32 pg_control_version; /* PG_CONTROL_VERSION */
134 uint32 catalog_version_no; /* see catversion.h */
135
136 /*
137 * System status data
138 */
139 DBState state; /* see enum above */
140 pg_time_t time; /* time stamp of last pg_control update */
141 XLogRecPtr checkPoint; /* last check point record ptr */
142
143 CheckPoint checkPointCopy; /* copy of last check point record */
144
145 XLogRecPtr unloggedLSN; /* current fake LSN value, for unlogged rels */
146
147 /*
148 * These two values determine the minimum point we must recover up to
149 * before starting up:
150 *
151 * minRecoveryPoint is updated to the latest replayed LSN whenever we
152 * flush a data change during archive recovery. That guards against
153 * starting archive recovery, aborting it, and restarting with an earlier
154 * stop location. If we've already flushed data changes from WAL record X
155 * to disk, we mustn't start up until we reach X again. Zero when not
156 * doing archive recovery.
157 *
158 * backupStartPoint is the redo pointer of the backup start checkpoint, if
159 * we are recovering from an online backup and haven't reached the end of
160 * backup yet. It is reset to zero when the end of backup is reached, and
161 * we mustn't start up before that. A boolean would suffice otherwise, but
162 * we use the redo pointer as a cross-check when we see an end-of-backup
163 * record, to make sure the end-of-backup record corresponds the base
164 * backup we're recovering from.
165 *
166 * backupEndPoint is the backup end location, if we are recovering from an
167 * online backup which was taken from the standby and haven't reached the
168 * end of backup yet. It is initialized to the minimum recovery point in
169 * pg_control which was backed up last. It is reset to zero when the end
170 * of backup is reached, and we mustn't start up before that.
171 *
172 * If backupEndRequired is true, we know for sure that we're restoring
173 * from a backup, and must see a backup-end record before we can safely
174 * start up.
175 */
181
182 /*
183 * Parameter settings that determine if the WAL can be used for archival
184 * or hot standby.
185 */
194
195 /*
196 * This data is used to check for hardware-architecture compatibility of
197 * the database and the backend executable. We need not check endianness
198 * explicitly, since the pg_control version will surely look wrong to a
199 * machine of different endianness, but we do need to worry about MAXALIGN
200 * and floating-point format. (Note: storage layout nominally also
201 * depends on SHORTALIGN and INTALIGN, but in practice these are the same
202 * on all architectures of interest.)
203 *
204 * Testing just one double value is not a very bulletproof test for
205 * floating-point compatibility, but it will catch most cases.
206 */
207 uint32 maxAlign; /* alignment requirement for tuples */
208 double floatFormat; /* constant 1234567.0 */
209#define FLOATFORMAT_VALUE 1234567.0
210
211 /*
212 * This data is used to make sure that configuration of this database is
213 * compatible with the backend executable.
214 */
215 uint32 blcksz; /* data block size for this DB */
216 uint32 relseg_size; /* blocks per segment of large relation */
217
218 uint32 slru_pages_per_segment; /* size of each SLRU segment */
219
220 uint32 xlog_blcksz; /* block size within WAL files */
221 uint32 xlog_seg_size; /* size of each WAL segment */
222
223 uint32 nameDataLen; /* catalog name field width */
224 uint32 indexMaxKeys; /* max number of columns in an index */
225
226 uint32 toast_max_chunk_size; /* chunk size in TOAST tables */
227 uint32 loblksize; /* chunk size in pg_largeobject */
228
229 bool float8ByVal; /* float8, int8, etc pass-by-value? */
230
231 /* Are data pages protected by checksums? Zero if no checksum version */
233
234 /*
235 * True if the default signedness of char is "signed" on a platform where
236 * the cluster is initialized.
237 */
239
240 /*
241 * Random nonce, used in authentication requests that need to proceed
242 * based on values that are cluster-unique, like a SASL exchange that
243 * failed at an early stage.
244 */
246
247 /* CRC of all above ... MUST BE LAST! */
250
251/*
252 * Maximum safe value of sizeof(ControlFileData). For reliability's sake,
253 * it's critical that pg_control updates be atomic writes. That generally
254 * means the active data can't be more than one disk sector, which is 512
255 * bytes on common hardware. Be very careful about raising this limit.
256 */
257#define PG_CONTROL_MAX_SAFE_SIZE 512
258
259/*
260 * Physical size of the pg_control file. Note that this is considerably
261 * bigger than the actually used size (ie, sizeof(ControlFileData)).
262 * The idea is to keep the physical size constant independent of format
263 * changes, so that ReadControlFile will deliver a suitable wrong-version
264 * message instead of a read error if it's looking at an incompatible file.
265 */
266#define PG_CONTROL_FILE_SIZE 8192
267
268/*
269 * Ensure that the size of the pg_control data structure is sane.
270 */
272 "pg_control is too large for atomic disk writes");
274 "sizeof(ControlFileData) exceeds PG_CONTROL_FILE_SIZE");
275
276#endif /* PG_CONTROL_H */
TransactionId MultiXactId
Definition c.h:746
uint64 MultiXactOffset
Definition c.h:748
uint64_t uint64
Definition c.h:625
uint32_t uint32
Definition c.h:624
#define StaticAssertDecl(condition, errmessage)
Definition c.h:1008
uint32 TransactionId
Definition c.h:736
#define PG_CONTROL_MAX_SAFE_SIZE
Definition pg_control.h:257
#define MOCK_AUTH_NONCE_LEN
Definition pg_control.h:28
DBState
Definition pg_control.h:98
@ DB_IN_PRODUCTION
Definition pg_control.h:105
@ DB_STARTUP
Definition pg_control.h:99
@ DB_SHUTDOWNING
Definition pg_control.h:102
@ DB_IN_ARCHIVE_RECOVERY
Definition pg_control.h:104
@ DB_SHUTDOWNED_IN_RECOVERY
Definition pg_control.h:101
@ DB_SHUTDOWNED
Definition pg_control.h:100
@ DB_IN_CRASH_RECOVERY
Definition pg_control.h:103
#define PG_CONTROL_FILE_SIZE
Definition pg_control.h:266
uint32 pg_crc32c
Definition pg_crc32c.h:38
int64 pg_time_t
Definition pgtime.h:23
unsigned int Oid
Oid oldestMultiDB
Definition pg_control.h:52
MultiXactId oldestMulti
Definition pg_control.h:51
MultiXactOffset nextMultiOffset
Definition pg_control.h:48
TransactionId newestCommitTsXid
Definition pg_control.h:56
TransactionId oldestXid
Definition pg_control.h:49
TimeLineID PrevTimeLineID
Definition pg_control.h:40
TimeLineID ThisTimeLineID
Definition pg_control.h:39
TransactionId oldestActiveXid
Definition pg_control.h:65
bool fullPageWrites
Definition pg_control.h:42
MultiXactId nextMulti
Definition pg_control.h:47
FullTransactionId nextXid
Definition pg_control.h:45
TransactionId oldestCommitTsXid
Definition pg_control.h:54
pg_time_t time
Definition pg_control.h:53
int wal_level
Definition pg_control.h:43
bool logicalDecodingEnabled
Definition pg_control.h:44
uint32 dataChecksumState
Definition pg_control.h:68
XLogRecPtr redo
Definition pg_control.h:37
Oid oldestXidDB
Definition pg_control.h:50
char mock_authentication_nonce[MOCK_AUTH_NONCE_LEN]
Definition pg_control.h:245
uint32 pg_control_version
Definition pg_control.h:133
uint32 xlog_seg_size
Definition pg_control.h:221
XLogRecPtr backupStartPoint
Definition pg_control.h:178
bool track_commit_timestamp
Definition pg_control.h:193
CheckPoint checkPointCopy
Definition pg_control.h:143
uint32 slru_pages_per_segment
Definition pg_control.h:218
XLogRecPtr backupEndPoint
Definition pg_control.h:179
XLogRecPtr minRecoveryPoint
Definition pg_control.h:176
uint32 data_checksum_version
Definition pg_control.h:232
XLogRecPtr unloggedLSN
Definition pg_control.h:145
uint32 indexMaxKeys
Definition pg_control.h:224
pg_time_t time
Definition pg_control.h:140
bool default_char_signedness
Definition pg_control.h:238
XLogRecPtr checkPoint
Definition pg_control.h:141
uint64 system_identifier
Definition pg_control.h:118
uint32 catalog_version_no
Definition pg_control.h:134
TimeLineID minRecoveryPointTLI
Definition pg_control.h:177
pg_crc32c crc
Definition pg_control.h:248
uint32 toast_max_chunk_size
Definition pg_control.h:226
uint64 XLogRecPtr
Definition xlogdefs.h:21
uint32 TimeLineID
Definition xlogdefs.h:63