`

oracle性能调整—PCTFREE、PCTUSED

阅读更多

一、定义

1、PCTFREE、PCTUSED使你能控制一个segment里所有数据块里free space的使用。
    PCTFREE:一个数据块保留的用于块里已有记录的可能更新的自由空间占block size的最小比例。
    PCTUSED:在新记录被插入block里之前这个block可以用于存储行数据和其他信息的空间所占的最小比率。

2、这两个参数的使用
    如果创建表的时候指定pctfree=20%,oracle会在这个表的data segment的每个block都保留20%的空间用于已有记录的更新。Block的已使用空间上升到整个block size的80%时,这个block将移出free list;在提交了delete、update之后,oracle server处理这条语句并检查对应block的已使用空间是否低于PCTUSED,如果是,则这个block放进free list。

3、PCTFREE、PCTUSED的设定
    • PCTFREE
    – Default 10
    – Zero if no UPDATE activity
    – PCTFREE = 100 × upd / (average row length)
    • PCTUSED
    – Default 40
    – Set if rows deleted
    – PCTUSED = 100 – PCTFREE – 100 × rows × (average row length) / blocksize
    其中,upd : the average amount added by updates, in bytes。This is determined by subtracting the average row length of intercurrent average row length;
    average row length:在运行了analyize命令之后,这个值可以从dba_tables中的avg_row_len列中获得。
    rows : the number of rows to be deleted before free list maintenance occurs。

4、Delete、update可以增加block的自由空间,但是释放出来的空间有可能是不连续的,oracle在下列情况下会对碎片进行整理:一个block有足够的自由空间容纳row piece,但是由于每个碎片都较小以至这个row piece不能存放在一个连续的section中。

 

 

二、Migration和Chaining

    1、如果一行的数据太大以至一个单独的block容纳不下,会产生两种现象:
    A、Chaining:行数据太大以至一个空block容纳不下,oracle会将这一行的数据存放在一个或多个block 组成的block chain中,insert、update都可能导致这个问题,在某些情况下row chaining是不能避免的。
    B、Migration:一次update操作可能导致行数据增大,以至它所在的block容纳不下,oracle server会去寻找一个有足够自由空间容纳整行数据的block,如果这样的block存在,oracle server把整行移到新的block,在原位置保存一个指向新存放位置的镜像行,镜像行的rowid和原来的rowid一致。
    Chaining、Migration的弊端:insert、update的性能降低,索引查询增加了IO次数。

    2、检测migration和chaining:
    Analyize table table_name compute statistics;[Page]
    Select num_rows,chain_cnt from dba_tables where table_name=’...’;
    查询镜像行:
    Analyize table table_name list chained rows;

    ORA-01495: 未找到指定的链接行表(注:如果 Chained_rows 表不存在,会有以上错误。可以通过@?\rdbms\admin\utlchain.sql 脚本创建该表。)
    Select owner_name,table_name,head_rowid from chained_rows where table_name=’...’;
    产生Migration的原因可能是由于PCTFREE设置的太低以至没有保留足够的空间用于更新。
    可以通过增加PCTFREE的值避免行镜像产生。

 

 

3、消除镜像行的步骤:
    运行analyize table ... list chained rows;
    复制镜像行到另一个表tmp;
    从源表中删除这些行;
    从tmp中将这些行插回到源表中。
    脚本:
    /* Get the name of the table with migrated rows */
    accept table_name prompt ’Enter the name of the table with migrated rows: ’
    /* Clean up from last execution */
    set echo off
    drop table migrated_rows;
    drop table chained_rows;
    /* Create the CHAINED_ROWS table */
    @?/rdbms/admin/utlchain
    set echo on
    spool fix_mig
    /* List the chained & migrated rows */
    analyze table &table_name list chained rows;
    /* Copy the chained/migrated rows to another table */
    create table migrated_rows as
    select orig.* from &table_name orig, chained_rows cr
    where orig.rowid = cr.head_rowid
    and cr.table_name = upper(’&table_name’);
    /* Delete the chained/migrated rows from the original table */
    delete from &table_name
    where rowid in ( select head_rowid from chained_rows );
    /* Copy the chained/migrated rows back into the original table */
    insert into &table_name select * from migrated_rows;
    spool off
    使用这个脚本时,必须将涉及到的外键约束去掉。

分享到:
评论

相关推荐

    Oracle数据库管理员技术指南

    2.1.18 怎样确定 PCTFREE 的最佳值 2.1.19 怎样决定 PCTUSED 的最佳值 2.1.20 怎样查找每个数据块的可用数据 区域 2.2 管理程序对象 2.2.1 怎样检查无效对象 2.2.2 怎样重新编译无效对象 2.2.3 在不同表空间...

    Oracle分区表和索引

     但是可以有不同的物理属性,比如pctfree, pctused, and tablespaces.  分区独立性:即使某些分区不可用,其他分区仍然可用。  最多可以分成64000个分区,但是具有LONG or LONG RAW列的表不可以,但是有CLOB or ...

    oracle_PLSQL_语法详细手册

    Pctfree 用来指定表中数据增长而在Oracle块中预留的空间. DEFAULT为10%,也就是说该表的每个块只能使用90%,10%给数据行的增大时使用. Pctused 用来指定一个水平线,当块中使用的空间低于该水平线时才可以向该中加入新...

    bbs论坛项目运用SSH框架Oracle数据库编写的一个简单示列项目

    pctfree 10 pctused 40 initrans 1 maxtrans 255 storage ( initial 64K minextents 1 maxextents unlimited ); -- Create/Recreate primary, unique and foreign key constraints alter table USERS ...

    Oracle 9i&10g编程艺术:深入数据库体系结构(全本)含脚本

    10.2.5 PCTFREE和PCTUSED 345 10.2.6 LOGGING和NOLOGGING 348 10.2.7 INITRANS和MAXTRANS 349 10.3 堆组织表 349 10.4 索引组织表 352 10.5 索引聚簇表 368 10.6 散列聚簇表 376 10.7 有序散列聚簇表 386 ...

    Oracle事例

    <3>.pctfree(index)=(maximum number of rows-initial number of rows)*100/maximum number of rows <4>.creating reverse key indexes sql> create unique index xay_id on xay(a) reverse pctfree 30 ...

    Oracle编程艺术

    第 1章 开发成功的Oracle应用程序...................................................... 61 1.1 我的方法................................................................................ 63 3 / 976 1.2 ...

    平安数据库试题

    Lower PCTUSED 6 ORACLE 9i 报 ORA-4031,从init参数文件哪个参数去入手解决 解释:共享池问题 答案:shared_pool_size 7 使用LOGMINER恢复archive log 文件,视图$logmnr_contents中不包含() a. archive logfile路径...

    Oracle 簇的使用详解

    建立顺序是:簇→簇表→簇索引→数据创建簇的格式CREATE CLUSTER cluster_name(column date_type [,column datatype]…)[PCTUSED 40 | integer] [PCTFREE 10 | integer][SIZE integer][INITRANS 1 | integer] ...

    中兴Oracle培训.PDF(高清)

    2.2 ORACLE实例..................................................................................................................................10 2.2.1 ORACLE进程........................................

    Toad 使用快速入门

    SQL 编辑器的主要功能是编辑、运行和调整SQL语句。TOAD 的高级编辑窗口包括众多的特性来提高开发人员编写SQL语句的产品化程度。例如,简单地生成代码模板,在编写SQL前自动发现包的内容和列的名字等等。 SQL编辑器...

Global site tag (gtag.js) - Google Analytics