|
9-2
[php]
* Block Packing Factors
参数PCTFREE and PCTUSED也称为packing factors, 通过storage子句中定义, 它们指的空余空间指除了:row数据,block header管理空间,overhead
PCTFREE
Free Space大于该百分比的block将作为update该block中row时使用,进入free list
PCTUSED
Used Space小于该百分比的block将作为insert(增加新row)考虑使用,进入free list
DELETE和UPDATE语句将影响free space, 释放的空间可能是不连续的, 比如处于block中间的row被删除
Oracle Server接合free sapce,当:
一个INSERT or UPDATE使用某个block,它包含有足够容纳下新row的free space
free space碎片没有一个连续的段(section),可以容纳row piece
由于对free space连续的压缩将影响性能,所以Oracle Server只有在上述情况下才进行接合操作
设置原则
PCTFREE
缺省=10, 如果没有update,可设置为0
PCTFREE = 100 × upd/(upd + ins)
PCTUSED
缺省=40
PCTUSED = 100 – PCTFREE – 100 × rows × (ins + upd) / blocksize
注: upd -- update时平均增加的字节数
ins -- insert时平均初始row length
rows -- is the number of rows to be deleted before free list maintenance occurs
-- 对free list维护发生之前删除的row数量 ??如何计算??
PCTUSED公式表明: 当block中有足够空间为多于一个row的update时,允许插入表 -- ???
对有很多insert的table,增大PCTUSED将改进block存储性能,blocks的密集存储可能引起free list竞争,但将使得请求的block更少,
table更小,读操作更快 -- 重点
对现存的table更改PCTFREE,PCTUSED将不能立刻起作用,将来的DML语句将按新的规则处理
* Migration and Chaining
Chaining: insert或update时,如果一个empty block无法容纳一个完整row,则发生row chaining,比如一个包含LOB的行,这种情况无法避免
加大DB_BLOCK_SIZE可以减少chain的发生
Migration: 当update增加数据时,如果原block无法容纳,则整个block移动到另一个有足够free space容纳下该行的block中,同时在原block中保留
original row piece,将一个链接指向实际存储block,这个migrated row的ROWID没有改变,所以index没有改变,仍指向原来的block
一般是PCTFREE过小引起的,使得UPDATE没有足够的空间
行迁移和行链接对性能都有很大影响
Insert,UPdate语句将引起额外的处理
查询语句将产生额外的I/O
Detecting Chaining and Migration
1. ANALYZE table COMPUTE STATISTICS; -- 分析存在迁移和链接的行数和占总行数的百分比
SELECT num_rows, chain_cnt FROM dba_tables -- 这里chain_cnt是chained和migrated的合计
WHERE table_name='...';
2. 使用UTLCHAIN.SQL创建表: chained_rows -- 使用下列语句直接创建也可以,列名必须相同
create table CHAINED_ROWS (
owner_name varchar2(30),
table_name varchar2(30),
cluster_name varchar2(30),
partition_name varchar2(30),
head_rowid rowid,
analyze_timestampdate );
ANALYZE table LIST CHAINED ROWS; -- 分析哪些行存在chained和migrated
SELECT owner_name, table_name, head_rowid
FROM chained_rows
WHERE table_name = '...';
OWNER_NAME TABLE_NAME HEAD_ROWID
---------- ---------- ------------------
SALES ORDER_HIST AAAAluAAHAAAAA1AAA
SALES ORDER_HIST AAAAluAAHAAAAA1AAB
3. V$SYSSTAT view or in report.txt
统计指标: table fetch continued row
Eliminating Migrated Rows
1. ANALYZE TABLE ... LIST CHAINED ROWS;
2. Copy the rows to another table.
3. Delete the rows from the original table.
4. Insert the rows from step 2 back into the original table.
Step 4 eliminates migrated rows because migration only occurs during an UPDATE operation.
-- 无法排除chained row
脚本示例: -- 注意,如果涉及外键约束,需先disable
/* 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 */
@ $ORACLE_HOME/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
[/php] |
|