postgresql disk storage structure

1.  Page header24Byte

1.1  Description

Recording information page header.

1.2.   Get_raw_page function

The content of the page specified table file returns, param1 : table name, param2 : main / FSM / vm, Param3: the first few pages

1.3.   Page_header (function)

effect:

Return to this page in the page header information. the param1 : get_raw_page return value of the function.

page before the 24 bytes of storage head data

Field:

       LSN : Record last modified on page xlog record

       Checksum : page checksum used to determine whether the current page complete

       flags :( indicates the current state of the page)

       Lower : page start pointer idle position

       UPER : This industry free end pointer position

       Special : page reserved position

       pageSize : page size

       Version : The current version

       prune_xid : Last delete or update the xid

       The page is stored behind the tuple ( tuple ) data information (data row of the table, a row is a tuple of information), which is the next section of the page item

1.4.  Illustration

 

2.   Page Item (inside pages stored tuple data)

A data (database rows) by the Item ID Tuple Header + Data + (actual data, written by the user) components.

Item Id and Page head stored together, an end of the page is present, Tuple Header + Data stored together, stored in the other end of the page.

For 1.5.   Item ID ( row pointer, 4 bytes )

       

 

1.6.   Tuple Header (tuple header, 23 bytes)

Description of data tuple data, this section describes the data (database rows) state, things id like.

Since the need to align the data store ( 8 integer multiple overall external length 24 bytes), the length of the blank line is 24 bytes. There are also four byte pointer. I.e., a blank line occupy a total of 24 + 4 = 28 bytes.

       

 

1.7.   Heap_page_items function

Show all lines on the stack pointer page. the param1 : get_raw_page return value of the function

       lp:

       lp_off: tuple position in the page

       lp_len: tuple actual length ( tuple header + Data , rounded to the final length required 8B integral multiple)

       t_xmin , t_xmax: things insertion, deletion and update of the above mentioned id , when inserted xmin written to the current transaction the above mentioned id , when you delete xmax write things the above mentioned id . Update also delete and then insert

       t_field3:

       t_ctid : physical ID , position for addressing data in the page (or for the index points to the next)

1.8.  Combat 1- single data memory for

L   SQL statement

       drop table if EXISTS test1;

create table test1(id int);

--vacuum analyze test1;

insert into test1 values(1);

select * from page_header(get_raw_page('test1', 'main', 0));

insert into test1 values(2);

select * from page_header(get_raw_page('test1', 'main', 0));

insert into test1 values(300);

select * from page_header(get_raw_page('test1', 'main', 0));

select * from heap_page_items(get_raw_page('test1',0));

l   Analysis

       It can be seen by the FIG., Each inserted into an int data, Lower increase in 4 -byte ( Item ID is written from the beginning of the page header, write header later), Upper reduced 32 bytes ( tuple is written from the beginning of the footer , tuple header + Data + = 24 = 28. 4 , as to take 8 integral multiple, it is 32 bytes).

t_data is stored in contents data, note the following marked red 2c010000 (actually 0X012c ) corresponding to the value of 300.

 

l  additional conclusions (to be determined)

According to the theory above, now, memory 4 byte int and 8 -byte int consumption of disk size is the same.

You can prove the following ways:

              drop table if EXISTS test1;

create table test1(id char(7));

insert into test1 values('a');

select * from page_header(get_raw_page('test1', 'main', 0));

insert into test1 values('b');

select * from page_header(get_raw_page('test1', 'main', 0));

insert into test1 values('c');

select * from page_header(get_raw_page('test1', 'main', 0));

select * from heap_page_items(get_raw_page('test1',0));

Description: char length may be specified manually, char in 7 actually occupies 8 bytes.

1.9.  Combat 2- stored amount calculating a single page ( 226 OK)

A single calculation can be stored int number of types of data

l   known

       page page default size is 8KB ( 8192 bytes)

page header 24 bytes

       Each row is inserted, a generating Item ID ( . 4 bytes) and a tuple ( tuple header + Data , a total of 32 bytes).

l   theoretical value

       (8192-24/ 36 = 226

(8192-24% 36 = 32

So in theory, it can be stored in a 226 row only one int data columns, belonging to space 32B

l   test sql

       drop table if EXISTS test1;

create table test1(id int);

insert into test1 select generate_series(1,226);

select * from page_header(get_raw_page('test1', 'main', 0));

select * from heap_page_items(get_raw_page('test1',0));

select count(*) from heap_page_items(get_raw_page('test1',0));

insert into test1 values(300);

l   Analysis

       Insert 226 Article data by page heaader see upper-lower = 32

       By page items to see the first page of the presence of 226 pieces of data.

       Then insert one found first page or 226 pieces of data, there is a second page of data

       Description The first page has been studded.

 

3. The  storage structure

l  storage There are 4 Zhong

PLAIN : avoid compression and external storage line.

EXTENDED : First compression, underwent external storage.

the EXTERNAL : Allow row outside the store, but not allowed to compress.

the MAIN : allows compression, try not to use the line outside the store more appropriate.

l  when compressed Tuple data

       When Tuple larger than about 2KB time, PostgreSQL will attempt based LZ compression compression algorithm.

l  When an external storage row ( the TOAST )

Outer rows of memory toasted intended property is of The Oversized-the Attribute the Storage Technique , for a long storage property alone. When a row of data exceeds PostgreSQL page size ( 8K later), this page will be placed in the system namespace pg_toast a separate table below, the original stored in a table in the TOAST pointer .

l  practical interpretation

create table tab3(id int primary key,info text);

 

Guess you like

Origin www.cnblogs.com/gc65/p/11011885.html