Line data Source code
1 : //!
2 : //! Misc constants, copied from PostgreSQL headers.
3 : //!
4 : //! Only place version-independent constants here.
5 : //!
6 : //! TODO: These probably should be auto-generated using bindgen,
7 : //! rather than copied by hand. Although on the other hand, it's nice
8 : //! to have them all here in one place, and have the ability to add
9 : //! comments on them.
10 : //!
11 :
12 : use crate::BLCKSZ;
13 : use crate::{PageHeaderData, XLogRecord};
14 :
15 : //
16 : // From pg_tablespace_d.h
17 : //
18 : pub const DEFAULTTABLESPACE_OID: u32 = 1663;
19 : pub const GLOBALTABLESPACE_OID: u32 = 1664;
20 :
21 : // From storage_xlog.h
22 : pub const XLOG_SMGR_CREATE: u8 = 0x10;
23 : pub const XLOG_SMGR_TRUNCATE: u8 = 0x20;
24 :
25 : pub const SMGR_TRUNCATE_HEAP: u32 = 0x0001;
26 : pub const SMGR_TRUNCATE_VM: u32 = 0x0002;
27 : pub const SMGR_TRUNCATE_FSM: u32 = 0x0004;
28 :
29 : //
30 : // From bufpage.h
31 : //
32 :
33 : // Assumes 8 byte alignment
34 : const SIZEOF_PAGE_HEADER_DATA: usize = std::mem::size_of::<PageHeaderData>();
35 : pub const MAXALIGN_SIZE_OF_PAGE_HEADER_DATA: usize = (SIZEOF_PAGE_HEADER_DATA + 7) & !7;
36 :
37 : //
38 : // constants from clog.h
39 : //
40 : pub const CLOG_XACTS_PER_BYTE: u32 = 4;
41 : pub const CLOG_XACTS_PER_PAGE: u32 = BLCKSZ as u32 * CLOG_XACTS_PER_BYTE;
42 : pub const CLOG_BITS_PER_XACT: u8 = 2;
43 : pub const CLOG_XACT_BITMASK: u8 = (1 << CLOG_BITS_PER_XACT) - 1;
44 :
45 : pub const TRANSACTION_STATUS_COMMITTED: u8 = 0x01;
46 : pub const TRANSACTION_STATUS_ABORTED: u8 = 0x02;
47 : pub const TRANSACTION_STATUS_SUB_COMMITTED: u8 = 0x03;
48 :
49 : pub const CLOG_ZEROPAGE: u8 = 0x00;
50 : pub const CLOG_TRUNCATE: u8 = 0x10;
51 :
52 : //
53 : // Constants from visibilitymap.h, visibilitymapdefs.h and visibilitymap.c
54 : //
55 : pub const SIZE_OF_PAGE_HEADER: u16 = 24;
56 : pub const BITS_PER_BYTE: u16 = 8;
57 : pub const HEAPBLOCKS_PER_PAGE: u32 =
58 : (BLCKSZ - SIZE_OF_PAGE_HEADER) as u32 * 8 / BITS_PER_HEAPBLOCK as u32;
59 : pub const HEAPBLOCKS_PER_BYTE: u16 = BITS_PER_BYTE / BITS_PER_HEAPBLOCK;
60 :
61 122489 : pub const fn HEAPBLK_TO_MAPBLOCK(x: u32) -> u32 {
62 122489 : x / HEAPBLOCKS_PER_PAGE
63 122489 : }
64 3233 : pub const fn HEAPBLK_TO_MAPBYTE(x: u32) -> u32 {
65 3233 : (x % HEAPBLOCKS_PER_PAGE) / HEAPBLOCKS_PER_BYTE as u32
66 3233 : }
67 3233 : pub const fn HEAPBLK_TO_OFFSET(x: u32) -> u32 {
68 3233 : (x % HEAPBLOCKS_PER_BYTE as u32) * BITS_PER_HEAPBLOCK as u32
69 3233 : }
70 :
71 : pub const BITS_PER_HEAPBLOCK: u16 = 2;
72 : pub const VISIBILITYMAP_ALL_VISIBLE: u8 = 0x01;
73 : pub const VISIBILITYMAP_ALL_FROZEN: u8 = 0x02;
74 : pub const VISIBILITYMAP_VALID_BITS: u8 = 0x03;
75 :
76 : // From xact.h
77 : pub const XLOG_XACT_COMMIT: u8 = 0x00;
78 : pub const XLOG_XACT_PREPARE: u8 = 0x10;
79 : pub const XLOG_XACT_ABORT: u8 = 0x20;
80 : pub const XLOG_XACT_COMMIT_PREPARED: u8 = 0x30;
81 : pub const XLOG_XACT_ABORT_PREPARED: u8 = 0x40;
82 :
83 : // From srlu.h
84 : pub const SLRU_PAGES_PER_SEGMENT: u32 = 32;
85 : pub const SLRU_SEG_SIZE: usize = BLCKSZ as usize * SLRU_PAGES_PER_SEGMENT as usize;
86 :
87 : /* mask for filtering opcodes out of xl_info */
88 : pub const XLOG_XACT_OPMASK: u8 = 0x70;
89 : pub const XLOG_HEAP_OPMASK: u8 = 0x70;
90 : /* does this record have a 'xinfo' field or not */
91 : pub const XLOG_XACT_HAS_INFO: u8 = 0x80;
92 :
93 : /*
94 : * The following flags, stored in xinfo, determine which information is
95 : * contained in commit/abort records.
96 : */
97 : pub const XACT_XINFO_HAS_DBINFO: u32 = 1u32 << 0;
98 : pub const XACT_XINFO_HAS_SUBXACTS: u32 = 1u32 << 1;
99 : pub const XACT_XINFO_HAS_RELFILENODES: u32 = 1u32 << 2;
100 : pub const XACT_XINFO_HAS_INVALS: u32 = 1u32 << 3;
101 : pub const XACT_XINFO_HAS_TWOPHASE: u32 = 1u32 << 4;
102 : // pub const XACT_XINFO_HAS_ORIGIN: u32 = 1u32 << 5;
103 : // pub const XACT_XINFO_HAS_AE_LOCKS: u32 = 1u32 << 6;
104 : // pub const XACT_XINFO_HAS_GID: u32 = 1u32 << 7;
105 :
106 : // From pg_control.h and rmgrlist.h
107 : pub const XLOG_NEXTOID: u8 = 0x30;
108 : pub const XLOG_SWITCH: u8 = 0x40;
109 : pub const XLOG_FPI_FOR_HINT: u8 = 0xA0;
110 : pub const XLOG_FPI: u8 = 0xB0;
111 :
112 : // From multixact.h
113 : pub const FIRST_MULTIXACT_ID: u32 = 1;
114 : pub const MAX_MULTIXACT_ID: u32 = 0xFFFFFFFF;
115 : pub const MAX_MULTIXACT_OFFSET: u32 = 0xFFFFFFFF;
116 :
117 : pub const XLOG_MULTIXACT_ZERO_OFF_PAGE: u8 = 0x00;
118 : pub const XLOG_MULTIXACT_ZERO_MEM_PAGE: u8 = 0x10;
119 : pub const XLOG_MULTIXACT_CREATE_ID: u8 = 0x20;
120 : pub const XLOG_MULTIXACT_TRUNCATE_ID: u8 = 0x30;
121 :
122 : pub const MULTIXACT_OFFSETS_PER_PAGE: u16 = BLCKSZ / 4;
123 : pub const MXACT_MEMBER_BITS_PER_XACT: u16 = 8;
124 : pub const MXACT_MEMBER_FLAGS_PER_BYTE: u16 = 1;
125 : pub const MULTIXACT_FLAGBYTES_PER_GROUP: u16 = 4;
126 : pub const MULTIXACT_MEMBERS_PER_MEMBERGROUP: u16 =
127 : MULTIXACT_FLAGBYTES_PER_GROUP * MXACT_MEMBER_FLAGS_PER_BYTE;
128 : /* size in bytes of a complete group */
129 : pub const MULTIXACT_MEMBERGROUP_SIZE: u16 =
130 : 4 * MULTIXACT_MEMBERS_PER_MEMBERGROUP + MULTIXACT_FLAGBYTES_PER_GROUP;
131 : pub const MULTIXACT_MEMBERGROUPS_PER_PAGE: u16 = BLCKSZ / MULTIXACT_MEMBERGROUP_SIZE;
132 : pub const MULTIXACT_MEMBERS_PER_PAGE: u16 =
133 : MULTIXACT_MEMBERGROUPS_PER_PAGE * MULTIXACT_MEMBERS_PER_MEMBERGROUP;
134 :
135 : // From heapam_xlog.h
136 : pub const XLOG_HEAP_INSERT: u8 = 0x00;
137 : pub const XLOG_HEAP_DELETE: u8 = 0x10;
138 : pub const XLOG_HEAP_UPDATE: u8 = 0x20;
139 : pub const XLOG_HEAP_HOT_UPDATE: u8 = 0x40;
140 : pub const XLOG_HEAP_INIT_PAGE: u8 = 0x80;
141 : pub const XLOG_HEAP2_VISIBLE: u8 = 0x40;
142 : pub const XLOG_HEAP2_MULTI_INSERT: u8 = 0x50;
143 : pub const XLH_INSERT_ALL_FROZEN_SET: u8 = (1 << 5) as u8;
144 : pub const XLH_INSERT_ALL_VISIBLE_CLEARED: u8 = (1 << 0) as u8;
145 : pub const XLH_UPDATE_OLD_ALL_VISIBLE_CLEARED: u8 = (1 << 0) as u8;
146 : pub const XLH_UPDATE_NEW_ALL_VISIBLE_CLEARED: u8 = (1 << 1) as u8;
147 : pub const XLH_DELETE_ALL_VISIBLE_CLEARED: u8 = (1 << 0) as u8;
148 :
149 : // From replication/message.h
150 : pub const XLOG_LOGICAL_MESSAGE: u8 = 0x00;
151 :
152 : // From rmgrlist.h
153 : pub const RM_XLOG_ID: u8 = 0;
154 : pub const RM_XACT_ID: u8 = 1;
155 : pub const RM_SMGR_ID: u8 = 2;
156 : pub const RM_CLOG_ID: u8 = 3;
157 : pub const RM_DBASE_ID: u8 = 4;
158 : pub const RM_TBLSPC_ID: u8 = 5;
159 : pub const RM_MULTIXACT_ID: u8 = 6;
160 : pub const RM_RELMAP_ID: u8 = 7;
161 : pub const RM_STANDBY_ID: u8 = 8;
162 : pub const RM_HEAP2_ID: u8 = 9;
163 : pub const RM_HEAP_ID: u8 = 10;
164 : pub const RM_LOGICALMSG_ID: u8 = 21;
165 :
166 : // from xlogreader.h
167 : pub const XLR_INFO_MASK: u8 = 0x0F;
168 : pub const XLR_RMGR_INFO_MASK: u8 = 0xF0;
169 :
170 : pub const XLOG_TBLSPC_CREATE: u8 = 0x00;
171 : pub const XLOG_TBLSPC_DROP: u8 = 0x10;
172 :
173 : pub const SIZEOF_XLOGRECORD: u32 = std::mem::size_of::<XLogRecord>() as u32;
174 :
175 : //
176 : // from xlogrecord.h
177 : //
178 : pub const XLR_MAX_BLOCK_ID: u8 = 32;
179 :
180 : pub const XLR_BLOCK_ID_DATA_SHORT: u8 = 255;
181 : pub const XLR_BLOCK_ID_DATA_LONG: u8 = 254;
182 : pub const XLR_BLOCK_ID_ORIGIN: u8 = 253;
183 : pub const XLR_BLOCK_ID_TOPLEVEL_XID: u8 = 252;
184 :
185 : pub const BKPBLOCK_FORK_MASK: u8 = 0x0F;
186 : pub const _BKPBLOCK_FLAG_MASK: u8 = 0xF0;
187 : pub const BKPBLOCK_HAS_IMAGE: u8 = 0x10; /* block data is an XLogRecordBlockImage */
188 : pub const BKPBLOCK_HAS_DATA: u8 = 0x20;
189 : pub const BKPBLOCK_WILL_INIT: u8 = 0x40; /* redo will re-init the page */
190 : pub const BKPBLOCK_SAME_REL: u8 = 0x80; /* RelFileNode omitted, same as previous */
191 :
192 : /* Information stored in bimg_info */
193 : pub const BKPIMAGE_HAS_HOLE: u8 = 0x01; /* page image has "hole" */
194 :
195 : /* From transam.h */
196 : pub const FIRST_NORMAL_TRANSACTION_ID: u32 = 3;
197 : pub const INVALID_TRANSACTION_ID: u32 = 0;
198 : pub const FIRST_BOOTSTRAP_OBJECT_ID: u32 = 12000;
199 : pub const FIRST_NORMAL_OBJECT_ID: u32 = 16384;
200 :
201 : pub const XLOG_CHECKPOINT_SHUTDOWN: u8 = 0x00;
202 : pub const XLOG_CHECKPOINT_ONLINE: u8 = 0x10;
203 : pub const XLP_FIRST_IS_CONTRECORD: u16 = 0x0001;
204 : pub const XLP_LONG_HEADER: u16 = 0x0002;
205 :
206 : /* From fsm_internals.h */
207 : const FSM_NODES_PER_PAGE: usize = BLCKSZ as usize - SIZEOF_PAGE_HEADER_DATA - 4;
208 : const FSM_NON_LEAF_NODES_PER_PAGE: usize = BLCKSZ as usize / 2 - 1;
209 : const FSM_LEAF_NODES_PER_PAGE: usize = FSM_NODES_PER_PAGE - FSM_NON_LEAF_NODES_PER_PAGE;
210 : pub const SLOTS_PER_FSM_PAGE: u32 = FSM_LEAF_NODES_PER_PAGE as u32;
211 :
212 : /* From visibilitymap.c */
213 : pub const VM_HEAPBLOCKS_PER_PAGE: u32 =
214 : (BLCKSZ as usize - SIZEOF_PAGE_HEADER_DATA) as u32 * (8 / 2); // MAPSIZE * (BITS_PER_BYTE / BITS_PER_HEAPBLOCK)
215 :
216 : // List of subdirectories inside pgdata.
217 : // Copied from src/bin/initdb/initdb.c
218 : pub const PGDATA_SUBDIRS: [&str; 22] = [
219 : "global",
220 : "pg_wal/archive_status",
221 : "pg_commit_ts",
222 : "pg_dynshmem",
223 : "pg_notify",
224 : "pg_serial",
225 : "pg_snapshots",
226 : "pg_subtrans",
227 : "pg_twophase",
228 : "pg_multixact",
229 : "pg_multixact/members",
230 : "pg_multixact/offsets",
231 : "base",
232 : "base/1",
233 : "pg_replslot",
234 : "pg_tblspc",
235 : "pg_stat",
236 : "pg_stat_tmp",
237 : "pg_xact",
238 : "pg_logical",
239 : "pg_logical/snapshots",
240 : "pg_logical/mappings",
241 : ];
242 :
243 : // Don't include postgresql.conf as it is inconvenient on node start:
244 : // we need postgresql.conf before basebackup to synchronize safekeepers
245 : // so no point in overwriting it during backup restore. Rest of the files
246 : // here are not needed before backup so it is okay to edit them after.
247 : pub const PGDATA_SPECIAL_FILES: [&str; 3] =
248 : ["pg_hba.conf", "pg_ident.conf", "postgresql.auto.conf"];
249 :
250 : pub static PG_HBA: &str = include_str!("../samples/pg_hba.conf");
|