row migeration:当发出update导致记录行长增加,block的剩余空间不足以存放这条记录,就会产生行迁移,发生行迁移时rowid不会改变,原来的block中会用一个指针存放这条记录在新的block中的地址,发生行迁移会对性能产生影响,因为读这条记录会读两个BLOCK。
row chain:当一个BLOCK不足以存放下一条记录的时候,就会发生行连接,这个时候oracle会把这条记录分成几个部分,分别存放在几个block中,然后把这几个block chain起来。行连接同样会影响性能,因为读一条记录至少会读两个BLOCK.
生产数据库的表claims的行迁移及行链接严重,此表为热表,性能越来越差,以下为消除表行迁移及行链接的操作过程。
SQL> select count(*) from mcsmaster.claims;
COUNT(*)
----------
146621
----------
146621
SQL> select chain_cnt from dba_tables where table_name='CLAIMS' AND WNER='MCSMASTER';
CHAIN_CNT
----------
119311
SQL> ALTER TABLE CLAIMS MOVE;
----------
119311
SQL> ALTER TABLE CLAIMS MOVE;
Table altered.
Elapsed: 00:00:05.17
SQL> ANALYZE TABLE CLAIMS COMPUTE STATISTICS;
ANALYZE TABLE CLAIMS COMPUTE STATISTICS
*
ERROR at line 1:
ORA-01502: index 'MCSMASTER.DOCSUBMIT_DATE_IND' or partition of such index is in unusable state
ANALYZE TABLE CLAIMS COMPUTE STATISTICS
*
ERROR at line 1:
ORA-01502: index 'MCSMASTER.DOCSUBMIT_DATE_IND' or partition of such index is in unusable state
Elapsed: 00:00:00.02
对表做完move后,表相关的索引将成unusable状态。在做move时一定要提前看下表所在表空间是否有足够的空间来做move动作。
SQL> SELECT INDEX_NAME,STATUS FROM USER_INDEXES WHERE TABLE_NAME='CLAIMS';
SQL> SELECT INDEX_NAME,STATUS FROM USER_INDEXES WHERE TABLE_NAME='CLAIMS';
INDEX_NAME STATUS
------------------------------ --------
CLAIMS_IDX23 UNUSABLE
CLAIMS_IDX22 UNUSABLE
CLAIMS_IDX21 UNUSABLE
CLAIMS_IDX20 UNUSABLE
CLAIMS_IDX19 UNUSABLE
CLAIMS_IDX18 UNUSABLE
CLAIMS_IDX2 UNUSABLE
CLAIMS_IDX1 UNUSABLE
CLAIMS_IDX8 UNUSABLE
CLAIMS_IDX7 UNUSABLE
CLAIMS_IDX6 UNUSABLE
------------------------------ --------
CLAIMS_IDX23 UNUSABLE
CLAIMS_IDX22 UNUSABLE
CLAIMS_IDX21 UNUSABLE
CLAIMS_IDX20 UNUSABLE
CLAIMS_IDX19 UNUSABLE
CLAIMS_IDX18 UNUSABLE
CLAIMS_IDX2 UNUSABLE
CLAIMS_IDX1 UNUSABLE
CLAIMS_IDX8 UNUSABLE
CLAIMS_IDX7 UNUSABLE
CLAIMS_IDX6 UNUSABLE
INDEX_NAME STATUS
------------------------------ --------
CLAIMS_IDX5 UNUSABLE
CLAIMS_IDX4 UNUSABLE
CLAIMS_IDX17 UNUSABLE
CLAIMS_IDX16 UNUSABLE
------------------------------ --------
CLAIMS_IDX5 UNUSABLE
CLAIMS_IDX4 UNUSABLE
CLAIMS_IDX17 UNUSABLE
CLAIMS_IDX16 UNUSABLE
15 rows selected.
下面对表索引进行一下rebuild
SELECT 'ALTER INDEX '||INDEX_NAME||' REBUILD;' FROM USER_INDEXES WHERE TABLE_NAME='CLAIMS';
SQL> ANALYZE TABLE CLAIMS COMPUTE STATISTICS;
Table analyzed.
SQL> select chain_cnt from user_tables where table_name='CLAIMS';
CHAIN_CNT
----------
3633
我们看到chain_cnt从146621降到了3633,说明大部分数据还是由update造成的行迁移。下面对剩下行链接的数据做处理。
目前数据库block size为8K 下面新建16K的表空间来存放有行链接的表claims
SQL> alter system set db_16k_cache_size=300m scope=both;
----------
3633
我们看到chain_cnt从146621降到了3633,说明大部分数据还是由update造成的行迁移。下面对剩下行链接的数据做处理。
目前数据库block size为8K 下面新建16K的表空间来存放有行链接的表claims
SQL> alter system set db_16k_cache_size=300m scope=both;
System altered.
SQL> create tablespace rowchain blocksize 16384 datafile 'd:\rowchain.dbf' size 300m;
Tablespace created.
SQL> alter table claims move tablespace rowchain;
Table altered.
SQL> analyze table claims compute statistics;
analyze table claims compute statistics
*
ERROR at line 1:
ORA-01502: index 'MCSMASTER.DOCSUBMIT_DATE_IND' or partition of such index is
in unusable state
analyze table claims compute statistics
*
ERROR at line 1:
ORA-01502: index 'MCSMASTER.DOCSUBMIT_DATE_IND' or partition of such index is
in unusable state
参照上面rebuild索引的步骤对表索引进行重建
SQL> ANALYZE TABLE CLAIMS COMPUTE STATISTICS;
Table analyzed.
Elapsed: 00:00:22.47
SQL> SELECT CHAIN_CNT FROM USER_TABLES WHERE TABLE_NAME='CLAIMS';
SQL> SELECT CHAIN_CNT FROM USER_TABLES WHERE TABLE_NAME='CLAIMS';
CHAIN_CNT
----------
0
----------
0
来自 “ ITPUB博客 ” ,链接:http://blog.itpub.net/23891491/viewspace-746609/,如需转载,请注明出处,否则将追究法律责任。
转载于:http://blog.itpub.net/23891491/viewspace-746609/