• Tablespace 的详细解读和高水位


    Tablespace  investigation

    DMS,HWM

    database   test

    Tablespacename = USERSPACE1

    1. USERSPACE1初始状态

     

    TablespaceExtent size (pages) = 32
    
    Totalnumber of pages = 8192
    
    Numberof usable pages = 8160
    
    Numberof used pages = 96
    
    Numberof pending free pages = 0
    
    Numberof free pages = 8064
    
    Highwater mark (pages) = 96

    这是tablespaceUSERSPACE1的初始状态,已经使用了3个extent。

    第一个数据块是表空间头

    第二个数据块是第一个SMP(SMP=SpaceMap Pages),用来跟踪第一组数据块的使用情况。

    第三个数据块是对象表,用来定位表空间中定义的对象。


    2.[db2inst1@oc5603811686~]$ db2 "create table tt1(id int)"


    TablespaceExtent size (pages) = 32
    
    Totalnumber of pages = 8192
    
    Numberof usable pages = 8160
    
    Numberof used pages = 160
    
    Numberof pending free pages = 0
    
    Numberof free pages = 8000
    
    Highwater mark (pages) = 160

    使用了64个pages,两个extent。


    3.[db2inst1@oc5603811686~]$ db2 "create table tt2(id int)"


    Totalnumber of pages = 8192
    
    Numberof usable pages = 8160
    
    Numberof used pages = 224
    
    Numberof pending free pages = 0
    
    Numberof free pages = 7936
    
    Highwater mark (pages) = 224

    一样的使用了64个pages,两个extent。


    4.[db2inst1@oc5603811686~]$ db2 "create table tt3(id int,notes longvarchar)"


    Totalnumber of pages = 8192
    
    Numberof usable pages = 8160
    
    Numberof used pages = 352
    
    Numberof pending free pages = 0
    
    Numberof free pages = 7808
    
    Highwater mark (pages) = 352


    使用了128个pages,4个extent。此次tt3表中有两个表对象。

    由此可以验证,每个表对象,至少分配两个数据块,一个是这个对象的extentmapEMP用来描述这个表对象的extents),另一个用来存储数据。


    5.[db2inst1@oc5603811686~]$ db2 drop table tt2

     

    Total number of pages = 8192
    
    Number of usable pages = 8160
    
    Number of used pages = 288
    
    Number of pending free pages = 64
    
    Number of free pages = 7808
    
    High water mark (pages) = 352


    删除表tt2后,释放了2extentUsedpages变成了288,但是HWM依然是352.


    LowerHigh Water Mark –降低高水位。


    1. DB 2 D A R T -- DB2 DATABASE ANALYSIS REPORTING TOOL

    注意使用db2dart工具时数据库连接要断开。


    [db2inst1@oc5603811686~]$db2darttest /dhwm


    ===========================================================
    
    Therequested DB2DART processing has completed successfully!
    
    Alloperation completed without error;
    
    noproblems were detected in the database.
    
    ===========================================================
    
    CompleteDB2DART report found in:TEST.RPT
    
    D A R T P R O C E S S I N G    C O M P L E T E

    结果放在当前目录TEST.RPT中。


    [db2inst1@oc5603811686~]$ more TEST.RPT


    Highwater mark: 352 pages, 11 extents (extents #0 - 10)
    
    
    [0000]65534 0x0e [0001] 65534 0x0e [0002] 65535 0x00 [0003] 40x40*
    
    [0004] 4 0x00* [0005] == EMPTY == [0006] == EMPTY == [0007] 60x40*
    
    [0008] 6 0x00* [0009] 6 0x42* [0010] 6 0x02*
    
    
    Dumphigh water mark processing - phase start.
    
    Numberof free extents below high water mark: 2
    
    Numberof used extents below high water mark: 9
    
    Objectholding high water mark:
    
    ObjectID: 6
    
    Type: Long Field Extent
    
    Note:Extent contains page #0 for object.

    通过ObjectID查看表信息。


    select * from syscat.tables where tbspaceid=2andtableid=6


    2.找到了占据HWM的表,怎样降低HWM呢?我们可以参考LHWM的建议。


    [db2inst1@oc5603811686~]$db2darttest /lhwm


    Pleaseenter tablespace ID, and number of pages (desired high water mark):


    注意该提示,为db2dart让我们输入的信息。Desiredhigh water mark,填上我们期望的高水位值。目前我们使用的pages数为288,然而HWM352,所以我们的期望值是288.

    输入:2288

    当然它给的建议不一定是我们期望的。


    3.使用RHWMRemoveHWM

    SMPSpaceMap Pages)块用来标识该映射的一组extent是否可用,如果一个空SMP占据了HWM,可以通过RHWM选项来降低。

    [db2inst1@oc5603811686~]$db2darttest /rhwm



    *表在离线重组(Reorg)时会保留原数据,同时在表空间内进行一份数据复制,当复制结束后删除原表数据块,如果HWM下没有足够的空间保存数据复制,则重组不但不能降低HWM,反而会导致HWM增加。


    9.7版本后的降低HWM方法


    1.db2alter tablespace userSPACE1 reduce MAX


    2.db2alter tablespace userSPACE1 lower high water mark



    继续探讨不同的表对象占用的extents数目,

     Used pages                           = 544
     Free pages                           = 7616

    带有constraint的表:

    [db2inst1@oc5603811686 db2dump]$ db2 "create table taba(cust_id integer not null,constraint cida unique(cust_id))"

     Used pages                           = 672
     Free pages                           = 7488

    计算可知,使用了4个extents,128个pages。我们可以看出,对db2而言这里有两个表对象,一个常规数据,一个constraint约束。


    带两个constraint的表:

    [db2inst1@oc5603811686 db2dump]$ db2 "create table taba2(cust_id integer not null,constraint cida unique(cust_id),constraint cida1 check (cust_id>10))"

     Used pages                           = 800
     Free pages                           = 7360

    计算可知,还是4个extents,128个pages,可以看出对于constraint,db2会向对待index一样,使用一个表对象来存储所有该类型数据。


    带有XML数据的表:

    [db2inst1@oc5603811686 db2dump]$ db2 "create table tab_xml(cust_id integer not null,address xml)"

     Used pages                           = 992
     Free pages                           = 7168

    计算可知,使用了6个extents,192个pages,是否是因为 not null约束占了2个extents呢?

    [db2inst1@oc5603811686 db2dump]$ db2 "create table tab_xml2(cust_id integer,address xml)"


     Used pages                           = 1184
     Free pages                           = 6976

    结果还是一样,由此可见xml占用了4个extents吗?


    仅带有not null约束的表:

    [db2inst1@oc5603811686 db2dump]$ db2 "create table tab_nn(cust_id integer not null)"


     Used pages                           = 1248
     Free pages                           = 6912

    使用了64个pages,2个extents,非常好。-------not null不会去占用分配一个constraint表对象。

    带有primary key约束的表:

    [db2inst1@oc5603811686 db2dump]$ db2 "create table tab_pk(cust_id integer not null primary key)"

     Used pages                           = 1376
     Free pages                           = 6784

    好小子,使用了128个pages,4个extents。 重试一遍。

     Used pages                           = 1504
     Free pages                           = 6656

    依然是。---primary key会分配占用一个constraint的表对象。


    topicNOT NULL constraints                             不占地儿


    topicUnique constraints

    SQL0542N  The column named "CUST_ID" cannot be a column of a primary key or
    unique key constraint because it can contain null values.  SQLSTATE=42831


    topicPrimary key constraints

    ----------------------------Unique 和 primary key 必须是指明not null,不能含有空值。 而且这两个constraint都会分配2个extents
    一定要注意这里,我们还可以通过建立unique index来约束一个值是否为唯一,不同的是,通过unique index是不需要保证not null的,可以允许一个空值。

    一共5个constraint,只用当有Unique constraints 和 primary key constraints时会对一个表对象,多分配两个extents。

    2013/07/20补充:

    今天在学习Oracle的时候读到,“Oracle系统将唯一性约束作为一般索引来对待,即唯一性索引是一个占用空间的对象”

    这样就很容易理解为什么DB2中unique constraints 和 primary key constraints时会会多分配两个extents,因为和Oracle一样的道理。


    有大对象(LOB)和XML数据的,这两种对象都会分配4个extents。

    MDC表,在基础数据类型外,也会分配4个extents。

    索引会占一个表对象,分配两个extents。

    表长字段对象,用来存储表中字段类型为long的数据,分配两个extents。


    分区表,看分了多少个区就乘以多少倍。











  • 相关阅读:
    formValidator表单验证
    js中判断一个对象的类型的种种方法
    利用jQuery中的serialize方法大量获取页面中表单的数据,发送的服务器
    用html和css写一个头部header和左侧菜单栏menu-bar固定的的页面
    关于刚才那个全选问题的解决
    关于input[type='checkbox']全选的问题
    用CSS来定义<p>标签,要求实现以下效果:字体颜色再IE6下为黑色,IE7下为红色,IE8下为绿色,其他浏览器下为黄色。
    Vue.js(20)之 封装字母表(是这个名字吗0.0)
    Vue.js之calendar组件
    书:构造器模式
  • 原文地址:https://www.cnblogs.com/jackhub/p/3147204.html
Copyright © 2020-2023  润新知