In-place upgrade:Storage

From PostgreSQL wiki
Jump to navigationJump to search



Storage

Page Layout Versions

PostgreSQL Version
7.4 8.0 8.1 8.2 8.3 8.4devel
Layout version 1 2 3 3 4 4
Header Size [B] 20 20 20 20 24 24
Tuple Header Size [B] 23 27 27 27 23 23
Tuple Header Aligned Size [B]

(MAX_ALIGN 4B/8B)

24/24 28/32 28/32 28/32 24/24 24/24
Tuple Header Aligned Size [B]

with null bit array (MAX_ALIGN=4B/8B)

28/32 32/32 32/32 32/32 28/32 28/32
Max TOAST Chunk Size [B]

(MAX_ALIGN=4B/8B)

?/? ?? 1994/1986 1994/1986 2000/1996 2000/1996

Page Header

Version 1

00       01       02       03       04       05       06       07       08       09       10       11       12       13       14       15          
+--------+--------+--------+--------+--------+--------+--------+--------+--------+--------+--------+--------+--------+--------+--------+--------+
|                          (XLogPtr) pd_lsn                             |         (uint32)pd_sui            |(uint16)pd_lower |(uint16)pd_upper |
|    (uint32)XLogPtr.xlogid         |      (uint32)XLogPtr.xrecoff      |                                   |                 |                 |
+--------+--------+--------+--------+--------+--------+--------+--------+--------+--------+--------+--------+--------+--------+--------+--------+

16       17       18       19       20   
+--------+--------+--------+--------+-------->
|    (uint16)     |pd_pagesize_\    | pd_linp[]			     
|   pd_special    |version(uint16)  |        
+--------+--------+--------+--------+-------->


Verison 2 & 3

Note: Page header is same for page layout 2 and 3.

00       01       02       03       04       05       06       07       08       09       10       11       12       13       14       15          
+--------+--------+--------+--------+--------+--------+--------+--------+--------+--------+--------+--------+--------+--------+--------+--------+
|                          (XLogPtr) pd_lsn                             |         (uint32)pd_tli            |(uint16)pd_lower |(uint16)pd_upper |
|    (uint32)XLogPtr.xlogid         |      (uint32)XLogPtr.xrecoff      |                                   |                 |                 |
+--------+--------+--------+--------+--------+--------+--------+--------+--------+--------+--------+--------+--------+--------+--------+--------+

16       17       18       19       20   
+--------+--------+--------+--------+-------->
|     (uint16)    |pd_pagesize_\    | pd_linp[]			     
|    pd_special   |version(uint16)  |        
+--------+--------+--------+--------+-------->

Version 4

00       01       02       03       04       05       06       07       08       09       10       11       12       13       14       15          
+--------+--------+--------+--------+--------+--------+--------+--------+--------+--------+--------+--------+--------+--------+--------+--------+
|                          (XLogPtr) pd_lsn                             | (uint16)pd_tli  |(uint16)pd_flags |(uint16)pd_lower |(uint16)pd_upper |
|    (uint32)XLogPtr.xlogid         |      (uint32)XLogPtr.xrecoff      |                 |                 |                 |                 |
+--------+--------+--------+--------+--------+--------+--------+--------+--------+--------+--------+--------+--------+--------+--------+--------+

16       17       18       19       20       21       22       23       24 
+--------+--------+--------+--------+--------+--------+--------+--------+-------->
|    (uint16)     |pd_pagesize_\    |       (uint32)pd_prune_xid        | pd_linp[]			     
|   pd_special    |version(uint16)  |                                   |
+--------+--------+--------+--------+--------+--------+--------+--------+-------->

Tuple Header

Version 1

00       01       02       03       04       05       06       07       08       09       10       11       12       13       14       15    
+--------+--------+--------+--------+--------+--------+--------+--------+--------+--------+--------+--------+--------+--------+--------+--------+
|         (uint32)t_xmin            |           (union)t_field2         |           (union)t_field3         |      (ItemPointerData)t_ctid                          
|                                   |   (uint32)t_cmin/(uint32)t_xmax   |   (uint32)t_cmax/(uint32)t_xvac   |          (uint32)ip_blkid         |
+--------+--------+--------+--------+--------+--------+--------+--------+--------+--------+--------+--------+--------+--------+--------+--------+

16       17       18       19       20       21       22       23   
+--------+--------+--------+--------+--------+--------+--------+-------->
   ... t_ctid     | (int16)t_natts  |     (uint16)    |(uint8) |        
|(uint16)ip_posid |                 |    t_infomask   | t_hoff |t_bits[]
+--------+--------+--------+--------+--------+--------+--------+-------->

Version 2 & 3

Note: Tuple header structure is same for version 2 and 3, but infomask content is little bit different.

00       01       02       03       04       05       06       07       08       09       10       11       12       13       14       15    
+--------+--------+--------+--------+--------+--------+--------+--------+--------+--------+--------+--------+--------+--------+--------+--------+
|         (uint32)t_xmin            |           (uint32)t_cmin          |          (uint32)t_xmax           |           (union)t_field4         |      
|                                   |                                   |                                   |   (uint32)t_cmax/(uint32)t_xvac   |
+--------+--------+--------+--------+--------+--------+--------+--------+--------+--------+--------+--------+--------+--------+--------+--------+

16       17       18       19       20       21       22       23       24       25       26       27  
+--------+--------+--------+--------+--------+--------+--------+--------+--------+--------+--------+-------->
|                (ItemPointerData)t_ctid              | (int16)t_natts  |     (uint16)    |(uint8) |        
|          (uint32)ip_blkid         |(uint16)ip_posid |                 |    t_infomask   | t_hoff |t_bits[]
+--------+--------+--------+--------+--------+--------+--------+--------+--------+--------+--------+-------->

Version 4

00       01       02       03       04       05       06       07       08       09       10       11       12       13       14       15    
+--------+--------+--------+--------+--------+--------+--------+--------+--------+--------+--------+--------+--------+--------+--------+--------+
|         (uint32)t_xmin            |           (uint32)t_xmax          |           (union)t_field3         |      (ItemPointerData)t_ctid                          
|                                   |                                   |   (uint32)t_cid/(uint32)t_xvac    |          (uint32)ip_blkid         |
+--------+--------+--------+--------+--------+--------+--------+--------+--------+--------+--------+--------+--------+--------+--------+--------+

16       17       18       19       20       21       22       23   
+--------+--------+--------+--------+--------+--------+--------+-------->
   ... t_ctid     |     (int16)     |     (uint16)    |(uint8) |        
|(uint16)ip_posid |   t_infomask2   |    t_infomask   | t_hoff |t_bits[]
+--------+--------+--------+--------+--------+--------+--------+-------->

Tuple info mask

Note: Page layout 4 introduces second infomask.

               01                         02                         03                         04           
   +--------------------------+--------------------------+--------------------------+--------------------------+
00 |      HEAP_HASNULL        |      HEAP_HASNULL        |      HEAP_HASNULL        |      HEAP_HASNULL        |
   +--------------------------+--------------------------+--------------------------+--------------------------+
01 |     HEAP_HASVARWIDTH     |     HEAP_HASVARWIDTH     |     HEAP_HASVARWIDTH     |     HEAP_HASVARWIDTH     |
   +--------------------------+--------------------------+--------------------------+--------------------------+
02 |     HEAP_HASEXTERNAL     |     HEAP_HASEXTERNAL     |     HEAP_HASEXTERNAL     |     HEAP_HASEXTERNAL     |
   +--------------------------+--------------------------+--------------------------+--------------------------+
03 |    HEAP_HASCOMPRESSED    |    HEAP_HASCOMPRESSED    |    HEAP_HASCOMPRESSED    |       HEAP_HASOID        |
   +--------------------------+--------------------------+--------------------------+--------------------------+
04 |       HEAP_HASOID        |       HEAP_HASOID        |       HEAP_HASOID        |         (UNUSED)         | 
   +--------------------------+--------------------------+--------------------------+--------------------------+
05 |        (UNUSED)          |         (UNUSED)         |        (UNUSED)          |       HEAP_COMBOCID      |  
   +--------------------------+--------------------------+--------------------------+--------------------------+
06 |    HEAP_XMAX_IS_XMIN     |         (UNUSED)         |   HEAP_XMAX_EXCL_LOCK    |   HEAP_XMAX_EXCL_LOCK    |
   +--------------------------+--------------------------+--------------------------+--------------------------+
07 |   HEAP_XMAX_UNLOGGED     |   HEAP_XMAX_UNLOGGED     |  HEAP_XMAX_SHARED_LOCK   |  HEAP_XMAX_SHARED_LOCK   |
   +--------------------------+--------------------------+--------------------------+--------------------------+
08 |   HEAP_XMIN_COMMITTED    |   HEAP_XMIN_COMMITTED    |   HEAP_XMIN_COMMITTED    |   HEAP_XMIN_COMMITTED    |
   +--------------------------+--------------------------+--------------------------+--------------------------+
09 |    HEAP_XMIN_INVALID     |    HEAP_XMIN_INVALID     |    HEAP_XMIN_INVALID     |    HEAP_XMIN_INVALID     |
   +--------------------------+--------------------------+--------------------------+--------------------------+
10 |   HEAP_XMAX_COMMITTED    |   HEAP_XMAX_COMMITTED    |   HEAP_XMAX_COMMITTED    |   HEAP_XMAX_COMMITTED    |
   +--------------------------+--------------------------+--------------------------+--------------------------+
11 |    HEAP_XMAX_INVALID     |    HEAP_XMAX_INVALID     |    HEAP_XMAX_INVALID     |    HEAP_XMAX_INVALID     |
   +--------------------------+--------------------------+--------------------------+--------------------------+
12 |  HEAP_MARKED_FOR_UPDATE  |  HEAP_MARKED_FOR_UPDATE  |    HEAP_XMAX_IS_MULTI    |    HEAP_XMAX_IS_MULTI    |
   +--------------------------+--------------------------+--------------------------+--------------------------+
13 |       HEAP_UPDATED       |       HEAP_UPDATED       |       HEAP_UPDATED       |       HEAP_UPDATED       |
   +--------------------------+--------------------------+--------------------------+--------------------------+
14 |      HEAP_MOVED_OFF      |      HEAP_MOVED_OFF      |      HEAP_MOVED_OFF      |      HEAP_MOVED_OFF      |
   +--------------------------+--------------------------+--------------------------+--------------------------+
15 |      HEAP_MOVED_IN       |      HEAP_MOVED_IN       |      HEAP_MOVED_IN       |      HEAP_MOVED_IN       |
   +--------------------------+--------------------------+--------------------------+--------------------------+


Varlen encoding

Legend
e ... external storage
c ... compressed
s ... size

prior 8.3

big endian
ecss ssss :: ssss ssss :: ssss ssss :: ssss ssss

d2 34 56 78 is external compressed datum, size is 12345678B


little endian
ssss ssss :: ssss ssss :: ssss ssss :: ecss ssss

78 56 34 d2 is external compressed datum, size is 12345678B

8.3 and later

big endian
0sss ssss                                        - uncompressed, unaligned data max 126 bytes long
1000 0000                                        - TOAST pointer
0css ssss :: ssss ssss :: ssss ssss :: ssss ssss - aligned data up to 1GB

7e          is internal 126 bytes unaligned long data
12 34 56 78 is internal uncompressed datum, size is 12345678B
52 34 56 78 is internal compressed datum, size is 12345678B


little endian
ssss sss0                                        - uncompressed, unaligned data max 126 bytes long
0000 0001                                        - TOAST pointer
ssss ssc0 :: ssss ssss :: ssss ssss :: ssss ssss - aligned data up to 1GB

FC          is internal 126 bytes unaligned long data
E0 59 D1 48 is internal uncompressed datum, size is 12345678B
E2 59 D1 48 is internal compressed datum, size is 12345678B