版权声明:本文为博主原创文章,未经博主允许不得转载。
一.准备知识:ORACLE的逻辑存储管理.
ORACLE在逻辑存储上分4个粒度:表空间,段,区和块.
1.1块:是粒度最小的存储单位,现在标准的块大小是8K,ORACLE每一次I/O操作也是按块来操作的,也就是说当ORACLE从数据文件读数据时,是读取多少个块,而不是多少行.每一个Block里可以包含多个row.
1.2区:由一系列相邻的块而组成,这也是ORACLE空间分配的基本单位,举个例子来说,当我们创建一个表Dave时,首先ORACLE会分配一区的空间给这个表,随着不断的INSERT数据到Dave,原来的这个区容不下插入的数据时,ORACLE是以区为单位进行扩展的,也就是说再分配多少个区给Dave,而不是多少个块.
1.3段:是由一系列的区所组成,一般来说,当创建一个对象时(表,索引),就会分配一个段给这个对象.所以从某种意义上来说,段就是某种特定的数据.如CREATE TABLE Dave,这个段就是数据段,而CREATE INDEX ON Dave(NAME),ORACLE同样会分配一个段给这个索引,但这是一个索引段了.查询段的信息可以通过数据字典: SELECT * FROM USER_SEGMENTS来获得.
1.4表空间:包含段,区及块.表空间的数据物理上储存在其所在的数据文件中.一个数据库至少要有一个表空间.
表空间(tableSpace)段(segment)盘区(extent)块(block)关系
当我们创建了一个表,即使我没有插入任何一行记录,ORACLE还是给它分配了8个块.当然这个跟建表语句的INITIAL参数及MINEXTENTS参数有关.如:
STORAGE
(
INITIAL 64K
MINEXTENTS 1
MAXEXTENTS UNLIMITED
);
也就是说,在这个对象创建以后,ORACLE至少给它分配一个区,初始大小是64K,一个标准块的大小是8K,刚好是8个BLOCK.
二.高水线(High Water Mark)
2.1官网说明如下
http://download.oracle.com/docs/cd/E11882_01/server.112/e16508/logical.htm#CNCPT89022
To manage space,Oracle Database tracks the state of blocks in the segment.The high water mark (HWM) is the point in a segment beyond which data blocks are unformatted and have never been used.
MSSM uses free lists to manage segment space.At table creation,no blocks in the segment are formatted.When a session first inserts rows into the table,the database searches the free list for usable blocks.If the database finds no usable blocks,then it preformats a group of blocks,places them on the free list,and begins inserting data into the blocks.In MSSM,a full table scan reads all blocks below the HWM.
ASSM does not use free lists and so must manage space differently.When a session first inserts data into a table,the database formats a single bitmap block instead of preformatting a group of blocks as in MSSM. The bitmap tracks the state of blocks in the segment,taking the place of the free list. The database uses the bitmap to find free blocks and then formats each block before filling it with data.ASSM spread out inserts among blocks to avoid concurrency issues.
Oracle自动段空间管理(ASSM:auto segment space management)
http://blog.csdn.net/tianlesoftware/archive/2009/12/07/4958989.aspx
Every data block in an ASSM segment is in one of the following states:
(1)Above the HWM
These blocks are unformatted and have never been used.
(2)Below the HWM
These blocks are in one of the following states:
(1)Allocated,but currently unformatted and unused
(2)Formatted and contain data
(3)Formatted and empty because the data was deleted
Figure 12-23depicts an ASSM segment as ahorizontal series of blocks. At table creation,the HWM is at the beginning of the segment on the left. Because no data has been inserted yet,all blocks in the segment are unformatted and never used.
Figure 12-23 HWM at Table Creation
Suppose that a transaction inserts rows into the segment. The database must allocate a group of blocks to hold the rows.The allocated blocks fall below the HWM.The database formats a bitmap block in this group to hold the Metadata,but does not preformat the remaining blocks in the group.
InFigure 12-24,the blocks below the HWM are allocated,whereas blocks above the HWM are neither allocated or formatted. As inserts occur,the database can write to any block with available space.The low high water mark (low HWM) marks the point below which all blocks are known to be formatted because they either contain data or formerly contained data.
InFigure 12-25,the database chooses a block between the HWM and low HWM and writes to it. The database could have just as easily chosen any other block between the HWM and low HWM,or any block below the low HWM that had available space. InFigure 12-25,the blocks to either side of the newly filled block are unformatted.
The low HWM is important in afull table scan.Because blocks below the HWM are formatted only when used,some blocks could be unformatted,as inFigure 12-25. For this reason,the database reads the bitmap block to obtain the location of the low HWM. The database reads all blocks up to the low HWM because they are known to be formatted,and then carefully reads only the formatted blocks between the low HWM and the HWM.
Assume that a new transaction inserts rows into the table,but the bitmap indicates that insufficient free space exists under the HWM. InFigure 12-26,the database advances the HWM to the right,allocating a new group of unformatted blocks.
Figure 12-26 Advancing HWM and Low HWM
When the blocks between the HWM and low HWM are full,the HWM advances to the right and the low HWM advances to the location of the old HWM. As the database inserts data over time,the HWM continues to advance to the right,with the low HWM always trailing behind it.Unless you manually rebuild,truncate,or shrink the object,the HWM never retreats.
二.高水线(High Water Mark)
2.1官网说明如下
http://download.oracle.com/docs/cd/E11882_01/server.112/e16508/logical.htm#CNCPT89022
To manage space,the HWM never retreats.
原文http://blog.csdn.net/tianlesoftware/article/details/4707900