Source code analysis of page Structure in PostgreSQL
Source code analysis of page Structure in PostgreSQL
In PG, the smallest Management Unit in disk storage and memory is page, which is also commonly referred to as block. Generally, the size of the PG page is 8 KB, which can be set during source code compilation. It cannot be changed since then, because many PG memory structure designs are based on this.
In a page, the table records are stored at the bottom of the page and then gradually increase. The Page structure is as follows:
A page structure, which consists of five parts:
Page Header: it is the page Header, which stores LSN and start offset and end offset of free space in the Page. I will discuss it later.
ItemId data: The index entries recorded in the table on the page. An index entry consists of four bytes: the offset and length of the record in the page.
Free space: The remaining available space in the page. It is not counted as the space marked as delete. It refers to the space that is not used at all, and is equivalent to the space not allocated in the page.
Item: refers to the records actually stored in the table.
Special space: stores the information of the index Access Method (AM: Access Method). Different index Access methods have different contents. However, if it is the page of the table, it is null and there is no information.
The source code is in src/backend/storage/page/bufpage. c. The following is Page initialization:
The 24 bytes of Page header are described as follows:
The source code of PageHeader is defined as follows:
Here, PageXLogRecPtr is a struct, 64-bit. Reason for recording xlog information:
Ensure the buffer manger WAL principle, that is, to write logs before writing data.
When dirty block checkpoint is used, logs are first flushed out to disk
In general, the structure of pages in PostgreSQL is similar to that in Oracle, and records are stored in ascending mode. However, the small details are relatively large. Oracle Block contains transaction-related information such as ITL.
------------------------------------ Lili split line ------------------------------------
Install PostgreSQL 6.3 on yum in CentOS 9.3
PostgreSQL cache details
Compiling PostgreSQL on Windows
Configuration and installation of LAPP (Linux + Apache + PostgreSQL + PHP) Environment in Ubuntu
Install and configure phppgAdmin on Ubuntu
Install PostgreSQL9.3 on CentOS
Configure a Streaming Replication cluster in PostgreSQL
How to install PostgreSQL 7/6 and phpPgAdmin in CentOS 5/6. 4
------------------------------------ Lili split line ------------------------------------
PostgreSQL details: click here
PostgreSQL: click here
This article permanently updates the link address: