9.3. Internal Layout of WAL Segment

A WAL segment is a 16 MB file by default, and it is internally divided into pages of 8192 bytes (8 KB). The first page has a header-data defined by the XLogLongPageHeaderData structure, while the headings of all other pages have the page information defined by the XLogPageHeaderData structure. Following the page header, XLOG records are written in each page from the beginning in descending order. See Fig. 9.7.

typedef XLogPageHeaderData *XLogPageHeader;

 * When the XLP_LONG_HEADER flag is set, we store additional fields in the
 * page header.  (This is ordinarily done just in the first page of an
 * XLOG file.)	The additional fields serve to identify the file accurately.
typedef struct XLogLongPageHeaderData
	XLogPageHeaderData std;		/* standard header fields */
	uint64		xlp_sysid;		/* system identifier from pg_control */
	uint32		xlp_seg_size;	/* just as a cross-check */
	uint32		xlp_xlog_blcksz;	/* just as a cross-check */
} XLogLongPageHeaderData;
 * Each page of XLOG file has a header like this:
#define XLOG_PAGE_MAGIC 0xD113	/* can be used as WAL version indicator */

typedef struct XLogPageHeaderData
	uint16		xlp_magic;		/* magic value for correctness checks */
	uint16		xlp_info;		/* flag bits, see below */
	TimeLineID	xlp_tli;		/* TimeLineID of first record on page */
	XLogRecPtr	xlp_pageaddr;	/* XLOG address of this page */

	 * When there is not enough space on current page for whole record, we
	 * continue on the next page.  xlp_rem_len is the number of bytes
	 * remaining from a previous page; it tracks xl_tot_len in the initial
	 * header.  Note that the continuation data isn't necessarily aligned.
	uint32		xlp_rem_len;	/* total len of remaining data for record */
} XLogPageHeaderData;
Fig. 9.7. Internal layout of a WAL segment file.

The XLogLongPageHeaderData structure and the XLogPageHeaderData structure are defined in src/include/access/xlog_internal.h. The explanation of both structures is omitted because they are not required in the following descriptions.