日期:2014-05-16  浏览次数:20521 次

Oracle 数据块(data block)的结构和解析

?First of all let’s create a new tablespace and a table:

SQL> create tablespace my_tbs datafile '/u01/oradata/chenlin/my_tbs.dbf' size 200m ;

?Tablespace created.

?then:

SQL> create table my_tab tablespace my_tbs as select * from dba_objects ?;

?Table created.

?Now let’s get more information about this table from DBA_SEGMENTS view:

SQL> select header_file, header_block, bytes, blocks, extents from dba_segments where segment_name='MY_TAB';


 HEADER_FILE   HEADER_BLOCK       BYTES        BLOCKS       EXTENTS
-----------    ------------           --------      ----------      ----------
  12                         17               4194304           1024        19

?

From the output we can say that the header block of the table is stored in the datafile 12, block 17.?

The size of the table 4194304 bytes (4.2 Mb) and it contains 1024 blocks and 19 extents.

After getting block size of the database, let’s do some math:


SQL> show parameter db_block_size


 NAME                                 TYPE        VALUE
--------------                  ----------- --------------------------
db_block_size                     integer     4096

?

BLOCKS (dba_segments) * DB_BLOCK_SIZE (parameter file) = BYTES (dba_segments)

so : 1024 * 4096 = ?4194304?


Now let’s query DBA_EXTENTS view to get some information on extents and data blocks of this table:?

SQL> col segment_name format a20

SQL> select segment_name, extent_id, block_id, ?blocks, bytes from dba_extents where segment_name='MY_TAB';

?SEGMENT_NAME EXTENT_ID BLOCK_ID BLOCKS BYTES

 --------------------  ----------   ----------    ----------   -------
MY_TAB                              0         17         16        65536
MY_TAB                              1         33         16        65536
MY_TAB                              2         49         16        65536
MY_TAB                              3         65         16        65536
MY_TAB                              4         81         16        65536
MY_TAB                              5         97         16        65536
MY_TAB                              6        113        16        65536
MY_TAB                              7        129        16        65536
MY_TAB                              8        145        16        65536
MY_TAB                              9        161        16        65536
MY_TAB                             10       177        16        65536
MY_TAB                             11       193        16        65536
    
.............................