4 * Definitions for the WAL record format.
6 * Portions Copyright (c) 1996-2014, PostgreSQL Global Development Group
7 * Portions Copyright (c) 1994, Regents of the University of California
9 * src/include/access/xlogrecord.h
14 #include "access/rmgr.h"
15 #include "access/xlogdefs.h"
16 #include "storage/block.h"
17 #include "storage/relfilenode.h"
18 #include "utils/pg_crc.h"
21 * The overall layout of an XLOG record is:
22 * Fixed-size header (XLogRecord struct)
30 * where there can be zero to four backup blocks (as signaled by xl_info flag
31 * bits). XLogRecord structs always start on MAXALIGN boundaries in the WAL
32 * files, and we round up SizeOfXLogRecord so that the rmgr data is also
33 * guaranteed to begin on a MAXALIGN boundary. However, no padding is added
34 * to align BkpBlock structs or backup block data.
36 * NOTE: xl_len counts only the rmgr data, not the XLogRecord header,
37 * and also not any backup blocks. xl_tot_len counts everything. Neither
38 * length field is rounded up to an alignment boundary.
40 typedef struct XLogRecord
42 uint32 xl_tot_len; /* total len of entire record */
43 TransactionId xl_xid; /* xact id */
44 uint32 xl_len; /* total len of rmgr data */
45 uint8 xl_info; /* flag bits, see below */
46 RmgrId xl_rmid; /* resource manager for this record */
47 /* 2 bytes of padding here, initialize to zero */
48 XLogRecPtr xl_prev; /* ptr to previous record in log */
49 pg_crc32 xl_crc; /* CRC for this record */
51 /* If MAXALIGN==8, there are 4 wasted bytes here */
53 /* ACTUAL LOG DATA FOLLOWS AT END OF STRUCT */
57 #define SizeOfXLogRecord MAXALIGN(sizeof(XLogRecord))
59 #define XLogRecGetData(record) ((char*) (record) + SizeOfXLogRecord)
62 * XLOG uses only low 4 bits of xl_info. High 4 bits may be used by rmgr.
64 #define XLR_INFO_MASK 0x0F
67 * If we backed up any disk blocks with the XLOG record, we use flag bits in
68 * xl_info to signal it. We support backup of up to 4 disk blocks per XLOG
71 #define XLR_BKP_BLOCK_MASK 0x0F /* all info bits used for bkp blocks */
72 #define XLR_MAX_BKP_BLOCKS 4
73 #define XLR_BKP_BLOCK(iblk) (0x08 >> (iblk)) /* iblk in 0..3 */
76 * Header info for a backup block appended to an XLOG record.
78 * As a trivial form of data compression, the XLOG code is aware that
79 * PG data pages usually contain an unused "hole" in the middle, which
80 * contains only zero bytes. If hole_length > 0 then we have removed
81 * such a "hole" from the stored data (and it's not counted in the
82 * XLOG record's CRC, either). Hence, the amount of block data actually
83 * present following the BkpBlock struct is BLCKSZ - hole_length bytes.
85 * Note that we don't attempt to align either the BkpBlock struct or the
86 * block's data. So, the struct must be copied to aligned local storage
89 typedef struct BkpBlock
91 RelFileNode node; /* relation containing block */
92 ForkNumber fork; /* fork within the relation */
93 BlockNumber block; /* block number */
94 uint16 hole_offset; /* number of bytes before "hole" */
95 uint16 hole_length; /* number of bytes in "hole" */
97 /* ACTUAL BLOCK DATA FOLLOWS AT END OF STRUCT */
100 #endif /* XLOGRECORD_H */