PostgreSQL Storage System 2: REDOLOG File Storage Structure

Source: Internet
Author: User

The naming method for Pg XLOG files (REDOLOG) names is defined in the XLogFileName macro, the time series ID, log ID, and segment ID are composed of eight hexadecimal numbers. For example, 000000000000000000008f.

# Define XLogFileName(Fname, tli, log, seg)\

Snprintf (fname, MAXFNAMELEN,"% 08X % 08X % 08X", Tli, log, seg)

Different segment IDs correspond to different physical XLOG log files. Log IDs are logical concepts and contain multiple physical XLOG files.

The initial size of the Pg XLOG file (often called REDOLOG) is set in the configure. in and configure files. The default size is 16 Mb. The size settings are as follows:

Wal_segsize = 16

XLOG_SEG_SIZE ($ {wal_segsize} * 1024*1024) = 16 M

The XLOG_SEG_SIZE is the segment size of the XLOG log file, which is the size of a physical log file. The size of a logical XLOG file is 4 Gb.

 

The storage format of Pg XLOG files is roughly as follows:

<PageHeaderData>

<XLogRecord>

<Rmgr-specific data>

<BkpBlock>

<XLogRecData> includes <CheckPoint> and so on.

<BkpBlock>

<XLogRecData>

<BkpBlock>

<XLogRecData>

......

 

1

First view <PageHeaderData>, Which corresponds to different situations.XLogLongPageHeaderDataOrXLogPageHeaderDataStructure.XLOGFile HeaderXLogLongPageHeaderDataStructure and some suitable scenarios,XLogPageHeaderDataThe page header used in the file. StructureXLogLongPageHeaderDataThe first member of is the structure.XLogPageHeaderData. The two structure definitions are as follows:

 

TypedefStructXLogLongPageHeaderData

{

XLogPageHeaderDataStd;/*Page header Structure*/

Uint64Xlp_sysid;/*Control FilePg_controlSystem identifier in*/

Uint32Xlp_seg_size;/* XLOGFile Size*/

Uint32Xlp_xlog_blcksz;/* XLOGFile page size*/

}XLogLongPageHeaderData;

 

The page header structure in the XLOG File

TypedefStructXLogPageHeaderData

{

Uint16Xlp_magic;/* WALVersion indicator*/

Uint16Xlp_info;/* Flag bits, see below */

TimeLineIDXlp_tli;/*Timeline of the first record on this page*/

XLogRecPtrXlp_pageaddr;/*This pageXLOGLocation*/

}XLogPageHeaderData;

The page header structure in the XLOG FileXLogPageHeaderDataMemberXlp_magicIndicatesWALVersion number. MemberXlp_tliIndicates the timeline and member of the first record on this page.Xlp_pageaddrIndicatesXLOGLocation. MemberXlp_infoIndicates whether the record that follows the page header is part of a cross-page record or whether the page header StructureXLogPageHeaderDataWhether it is in the file header StructureXLogLongPageHeaderData. The value is defined as follows:

When a record is displayed across pages, set a flag in the header next to the record.

# DefineXLP_FIRST_IS_CONTRECORDZero x 0001

This indicates a long page header (mostly used for the first page of the file)

# DefineXLP_LONG_HEADERZero x 0002

All Flags defined in xlp_info (used for header validity check)

# DefineXLP_ALL_FLAGSZero x 0003

If the memberXlp_infoThe value isXLP_FIRST_IS_CONTRECORDThe header is followed by a cross-page structure.

XLOG File Header StructureXLogLongPageHeaderDataMemberXlp_seg_sizeIndicatesXLOGFile size. The default value is16 M. InThe configuration format in configure. in and configure files is as follows:

Wal_segsize = 16

XLOG_SEG_SIZE ($ {wal_segsize} * 1024*1024) = 16 M

MemberXlp_xlog_blckszThe page size in the file. The default value is 8 k.

  • 1
  • 2
  • 3
  • Next Page

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.