zoukankan      html  css  js  c++  java
  • 专题实验 Storage structure 物理存储

    物理存储结构主要是指: extent的分配, 以及datablock 存储相关, 置于tablespace, segment 都是逻辑结构.

    • tablespace : 逻辑结构, 没有实际物理存储.
    • segment : 逻辑结构, 比如一个表, 索引等 object, 每次按照extent分配.
    • extent : 物理结构,  物理上连续的 data block, 是一次分配的最小单位, extent 与 extent 之间可以是不连续的, 但是extent 内部的data block 是连续的. extent可以来自于表空间中不同的数据文件, 所以 segment 才可以横跨多个datafile, 但是一个extent内部的data block 是只能属于某一个datafile的.
    • datablock, 物理结构, 对应操作系统的物理文件块.

    extent

    extent 分配存储的优先级

    segment 大于 tablespace 大于 oracle default. (这里指的是 怎么分配 extent)

    一般创建表空间时会指定extent分配原则:

    create tablespace USER_LEON
    datafile '/opt/oracle/oradata/leon/leon01.dbf' size 10M
    extent management LOCAL uniform size 128k
    segment space management auto;

    extent management 就是指 extent的分配和管理办法: (参考以上代码)

    现在都是使用 LOCAL 管理办法, 在LOCAL 管理办法中又分为: 自动分配(autoallocate) 和 统一分配(uniform)

    extent management local autoallocate: 人为管理比较少, 小表适合

    extent management local uniform size 128k: 每次分配extent都是128k, 人为管理多, 碎片化小

    datablock

    这里主要对应上边代码 segment space management auto; 这句, 这表示自动管理表空间 datablock.

    推荐使用自动管理表空间

    这里主要说一下, datablock 的内部结构:

    • block header: the data block address, table directory, row directory, and transaction slots that are used when transactions make changes to rows in the block. (从上到下)
    • data space: row data is inserted into the block from bottom up. (从下到上)
    • Free space: the free space in a block is in the middle of the block thus both the header and the row data space can grow when necessary, the free space in a block is coninguous initally, however, deletions and updates may fragment the free space in the block, the free space in the block is coalesced by teh oracle when nessary.

    image

    参数

    initrans, maxtrans: specify the initial and the maximum number of transaction slots(事务槽)that are created in an index or a data block, the transaction slots are used to store information about transactions that are making changes to the block at a point in time. 可以控制并发.

    事务要修改块中的数据, 必须获得该块中的一个 itl (事务槽), 通过 itl 和 undo segment header 中的 transaction table, 可以知道事务处于活动阶段, 还是已经完成. 事务在修改块时(起始就是在修改行) 会检查行中 row header 中的标志位, 如果该标志位为 0 (该行没有被活跃的事务锁住, 这是可能要进行 deferred block clenaout 等工作), 就把该标志修改为事务在该块获得的 itl 序号, 这样当前事务就获得了对记录的锁定, 然后就可以修改数据了, 这也就是 oracle 行锁实现的原理.

    ITL 也叫事务槽, 它位于 block header.

    一个事务可能涉及多个BLOCK的更改, 所以一个事务可能在多个block 中产生 ITL 信息.

    PCTFREE for a data segment specifies the percentage of space in each data block reserved for growth resulting from updates to rows in the block .最少有多少空闲空间,为了已存在数据的扩张,比如 update 当前已存在的数据。比如 10%

    为什么要留出空间来呢? 这个留出空间的意思是,当这个 datablock 存储到一定程度的时候,剩下的空间是不能再继续往里存储数据的,这是为什么呢?

    因为需要留下这些空间为了 已经存储在这个 data block 里的数据被修改使用的,比如这个 data block里的数据被修改了,尤其是增大了,那么需要把相关内容

    存储在这个data block中,所以要预留一些空间.

    PCTUSED for a data segment represents the minimum percentage of used space that the Oracle server tries to maintain for each data block of the table. 默认 40%

    A block is put back on the free list when its used space falls below PCTUSED. The free list of a segment is a list of blocks that are candidates for accommodating future inserts. A segment, by default, is created with one free list, Segments can be created with a higher number of free lists by setting the FREELISTS parameter of the storage clause. The default for PCTUSED is 40%.

    Both PCTFREE and PCTUSED are calclated as percentages of available data space, that is, the block space that remains after deducting the header space from the total block size.

    下边的链表叫空闲链表,首先pctused这个概念必须是删除数据时相关,即当一个新块,你往里边插数据,没关系,你可以插入到该块的90%都没有问题,但是当你删除该块的数据,就必须要删除的40%已下之后,这个块才会被放置到空闲链表上,你才可以继续向该块插入数据(从空闲链表上找到该数据块)

    作用是 : 比如要插入数据到 datablock 中, extent内部 有个链表 free list,链表上的节点就是个个 data block ( 那些存储的数据小于 PCTUSED 的 datablock) 即当新插入数据时, oracle 会自动找那些存储空间多的地方插入,判断的依据就是 PCTUSED )

    PCTFREE , PCTUSED 单位都是 %

    PCTUSED 参数用于决定一个数据快(data block) 是否可被用于插入新数据(放置在空闲链表中),她的依据是数据区(rowdata)与数据块头(overhead))的容量之和占数据块全部容量的最大百分比

    当一个数据块中的可用空间比例小于 PCTUSED 参数的规定时,ORACLE就认为此数据块无法被用于插入新数据,直到数据块中的占用容量比例小于PCTUSED参数的限定

    举例说明

    假设你一个块可以存放100个数据,而且PCTFREE 是10,PCTUSED是40,则:不断的向块中插入数据,如果当存放到90个时,就不能存放新的数据,这是受pctfree来控制,预留的空间是给UPDATE用的。注意, 这时, 这个块会被从 freelist 空闲表中拿出来, 所以不能再插入数据了.

    当你删除一个数据后,再想插入个新数据行不行?不行,因为这个块还没有别拿到freelist上, 必须是删除41个,即低于40个以后才能插入新的数据的,这是受pctused来控制的。

    注意:如果表空间上启用了ASSM,在建立表的时候,只能指定PCTFREE,否则可用指定PCTFREE和PCTUSED。

    如果使用自动管理表空间, 不需要设置pctused.

    置于 pctfree, 要看这个表被修改的多不多, 如果需要频繁被修改, 则可能需要多余 10% 的 pctfree.

  • 相关阅读:
    Tomcat的SessionID引起的Session Fixation和Session Hijacking问题
    别把项目成功当目标!——项目经理的误区(1)(转)
    技术,项目经理的命?——项目经理的误区(3)(转)
    项目管理中,最难管的是什么?(转)
    项目经理的超越(三)人际优先,做事上的超越(转)
    大丈夫不可一日无权啊!——项目经理的误区(2)(转)
    舌尖上的职场(二)一起去吃饭吧!(转)
    舌尖上的职场(一)你最近还好吗?(转)
    【项目经理之修炼(10)】《初级篇》人际关系问题也是可以避免的(转)
    gcc与g++区别
  • 原文地址:https://www.cnblogs.com/moveofgod/p/3817849.html
Copyright © 2011-2022 走看看