rebuild和rebuild online的区别(metalinkNote:272762.1 )
前天应用服务器发现有个表不能往数据库插入数据一直报错,报错信息ora-01502:index’ or partition of such index is in unusable state 错误,原来是索引无效了,这个表是个分区表,数据量反查大,一个分区几千万的数据,这个索引又是全局索引,没有办法,工作时间不能停止业务,而且有大量数据要入库,数据为车辆的秒级数据,只好对索引做ONLINE REBUILD了。
做了ONLINE rebuild,可把我忙坏了,你猜怎么的,原来的UNDO和临时表空间马上不够用了,先扩展到一定的大小,然后发现数据库空间不够用了,又不断的产生归档,我就不停的删归档啊,就这样一直持续到下午4点多才重新建立完索引,也太慢了,由于删除了归档,没有办法,而外重新做了此RMAN备份最新的数据。真是折腾的一天,明天查下为什么索引失效。
查了下,为什么做ONILNE REBUILD这么慢的原因:
========
- Online Index rebuild takes a long time.
- ONLINE INDEX REBUILD SCANS THE BASE TABLE AND NOT THE INDEX
Symptoms:
=========
Performance issues while rebuilding very large indexes.
- The offline rebuilds of their index is relatively quick -finishes in 15minutes.
- Issuing index rebuild ONLINE statement => finishes in about an hour.
- This behavior of ONLINE index rebuilds makes it a non-option for large tables
as it just takes too long to scan the table to rebuild the index. The offlinemay not be feasible due to due to the 24/7 nature of the database.
- This may be a loss of functionality for such situations.
- If we attempt to simultaneously ONLINE rebuild the same indexes we may encounterhanging behavior indefinitely (or more than 6 hours).
DIAGNOSTICANALYSIS:
--------------------
We can trace the sessions rebuilding the indexes with 10046 level 12.
Comparing the IO reads for the index-rebuild and the index-rebuild-onlinereveals the following:
-ONLINE indexrebuilds
It scans thebase table and it doesn't scan the blocks of the index.
-OFFLINE index rebuilds
It scans the index for the build operation.
- This behaviour is across all versions.
Cause
Cause/Explanation
=============
When you rebuild index online,
- it will do a full tablescan on thebase table.
- At the same time it will maintaina journal table for DML data, which has changed during this index rebuildingoperation.
So it shouldtake longer time, specially if you do lots of DML on the same table,whilerebuilding index online.
On the other hand, while rebuilding the index without online option, Oraclewill grab the index in X-mode and rebuild a new index segment by selecting thedata from the old index. So here we are
- not allowing any DML on the table hence there is nojournal table involved
- and it is doing an index scan
Hence it will be pretty fast.
Fix
Solution/Conclusion:
===========
- The ONLINE index rebuild reads the base table, and this is by design.
- Rebuilding index ONLINE is pretty slow.
- Rebuilding index offline is very fast, but it prevents any DML on the basetable.
这次操作中的重新建立索引online 很慢是有原因的,rebuild online的同时可以同时进行dml操作的,但是online会维护一个操作日志,会使rebuild时间大幅加长。而offline的话又会给业务造成停机,具体使用看情况了。
2012-02-11
今天又发现了个超级大表用的,数据量大约2亿条,竟然还是全局索引,疯掉了,只要进行分区操作全局索引肯定失效,没有办法,为了将来更大的数据量着想,必须删除重新建立,这次我申请了停机维护,用了一个晚上的时间,创建索引的语句加了并行和nologging,如下:
CREATE INDEX XMJL.IDX_GTTC_VTR_DATE ON XMJL.GIS_TEST_TYGJ_CELLDATA
(VTR_ID, REC_DATE)
之前我没有用并行,结果一天过去了,索引才建立了3分之一还不到,真是悲催!