Oracle数据库的PCTFREE与PCTUSED

首先需要介绍一下行链接(Row chaining) 和行迁移(Row migrating)

【行链接】:当一行数据被insert时,可能造成数据块无法容纳的情况,oracle会将这行数据存储在一个数据块链之中。
比如insert一个数据类型为long或者long raw列的数据行,此时行链接不可避免。

【行迁移】:当一行数据被update时,可能导致长度变长,原数据块的可用空间无法容纳增长后的数据行。
oracle会将这行数据迁移到新的数据块中,并在原来所在位置保存一个指向新数据块的指针,被迁移的数据行rowid保持不变。
(Oracle preserves the original row piece of a migrated row to point to the new block containing the migrated row. The rowid of a migrated row does not change.)
——摘自oracle 10g concepts


不难得出结论:当发生行链接or行迁移时,I/O性能将下降。因为这将访问超过1个以上的数据块。



在手动管理的表空间(manually managed tablespaces)中,
用户可以通过PCTFREE和PCTUSED这两个存储参数来控制insert和update时剩余空间的使用。

NOTE:
PCTFREE不适用于LOB数据类型(包括BLOB,CLOB,NCLOB,和BFILE)


【PCTFREE】

PCTFREE参数用来设置至少需要保留的可用空间百分比,为了可能会发生的更新操作。
指定方法可以通过create table时加入pctfree 20这样的语句。

下述例子意味着块中行数据区与块头的容量之和不超过块大小的80%。






【PCTUSED】

PCTUSED用于决定一个数据块是否可被用于插入新数据。
指定方法可以通过create table时加入pctused 40这样的语句。

下述例子中,PCTUSED为40,即直到低于40%之后,才可以插入。







使用PCTFREE和PCTUSED参数管理数据库的可用空间:




上述例子中,PCTFREE为20,PCTUSED为40。
step 1 :数据块已使用空间比例小于80%才可有新的数据行插入,因为PCTFREE为20,意味着必须保留20%的剩余空间用于更新已存在的数据。
step 2 : 块内的剩余空间将用于更新已存在的数据,不能有新的数据行被插入,直到块内已使用空间比例小于39%时。
step 3 : 当块内已用空间低于40%时,新的行可以被插入。
step 4 : 同step1,此过程往复循环。



在新分配的数据块中:
insert的可用空间=数据块总大小—块头—PCTFREE
update的可用空间=PCTFREE


再深入一些了解向数据块中插入数据(来自oracle 10g concepts ):
For each data and index segment, Oracle maintains one or more free lists—lists of data blocks that have been allocated for that segment's extents and have free space greater than PCTFREE. These blocks are available for inserts. When you issue an INSERT statement, Oracle checks a free list of the table for the first available data block and uses it if possible. If the free space in that block is not large enough to accommodate the INSERT statement, and the block is at least PCTUSED, then Oracle takes the block off the free list. Multiple free lists for each segment can reduce contention for free lists when concurrent inserts take place.

After you issue a DELETE or UPDATE statement, Oracle processes the statement and checks to see if the space being used in the block is now less than PCTUSED. If it is, then the block goes to the beginning of the transaction free list, and it is the first of the available blocks to be used in that transaction. When the transaction commits, free space in the block becomes available for other transactions.


大意是:
在每个数据段(data segment)与索引段(index segment)中,Oracle管理着一个或多个可用块列表(free list)--其中列出了所有属于此段的数据扩展(extent),且可用空间比例大于 PCTFREE 限定的数据块。这些块可以被插入(insert)操作使用。当用户提交了 INSERT 语句后,Oracle从可用块列表中选择第一个有效的数据块使用。如果此数据块的可用空间不够容纳 INSERT 语句提交的数据,且此块的占用容量已经超过PCTUSED 的限定,Oracle就将其从可用块列表中移出。一个段可以同时使用多个可用块列表,以减少对一个表进行并发插入(concurrent insert)时产生的竞争。

当用户提交了 DELETEUPDATE 语句后,Oracle处理语句并检查相关数据块中的占用空间比例是否小于 PCTUSED 的规定。如果满足,那么这个数据块就被放入当前事务(transaction)正在使用的可用块列表(free list)的头部,如果当前事务还需要写入数据,此块将被首先使用。当事务提交后,此数据块中的可用空间还可被其他事务使用。



作者公众号(持续更新)

来自 “ ITPUB博客 ” ,链接:http://blog.itpub.net/29773961/viewspace-1419147/,如需转载,请注明出处,否则将追究法律责任。

转载于:http://blog.itpub.net/29773961/viewspace-1419147/

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值