一朋友就說rebuild index 報ORA-01652錯誤。並且temporary tablespace 是足夠大的。 rebuild 索引是6G,indextablespace 剩餘空間是2G。讓朋友把index tablespace 空間增加10G,在rebuild index成功。
之前整理過的一篇有關rebuildindex 的文章:
Oracle alter index rebuild 說明
關於這個問題MOS 上有2篇文檔進行了相關的說明:[ID 94178.1] 和 [ID 120360.1]。
執行如下命令時:
ALTER INDEX REBUILD or
ALTER TABLE MODIFY PARTITION REBUILD LOCALINDEXES
可能會遇到ORA-01652的錯誤, 該錯誤詳細解釋如下:
ORA-01652:unable to extend temp segment by %s in tablespace %s
Cause: Failed to allocate an extent for temp segmentin tablespace.
Action:Use ALTER TABLESPACE ADD DATAFILE statement to add one or more files to thetablespace indicated or create the object in other tablespace.
解決方案:
You will have to increase the amount of available free space in the index tablespaceeither by adding another datafile or enabling autoextend on an existingdatafile.
--增加索引資料表空間添加資料檔案或者將資料檔案改成autoextend。
解釋:
Thetablespace in the error message is pointing to the index's tablespace insteadof the user's default temporary tablespace.
During an index rebuild, there are two types oftemporary segments involved.
First, there are the temporarysegments that are used to store partial sort data when the SORT_AREA_SIZE istoo small to process the complete sort set. These segments are built in theuser's default TEMPORARY tablespace.
Second, as the index is being rebuilt, it uses a segment which is defined as atemporary segment until the rebuild is complete. Once this segment is fully populated,the old index can be dropped and this temporary segment is redefined as apermanent segment with the index name.
--在索引rebuild 期間,會產生2種temporary segments。
第一種是用來排序的temporarysegments,當SORT_AREA_SIZE 的值太小時,該segments 會在使用者預設的temporary tablespace 空間分配。
第二種是在使用者索引空間的segments,在rebuild index時,會分配一個temporary segment 來儲存索引的資訊,當rebuild 結束之後,old index 被droped 掉,之前分配的temporary segments 會定義為permanent segment。
所以對索引進行rebuild 至少要提供1倍以上的空閑空間來存放temporary segment。 否則就會出現ORA-01652的錯誤。
The error you are seeing is probably due to there being insufficient room in theindex's tablespace to hold both the original index and the new version concurrently.The new version of the index, currently a temp segment, will be in thetablespace where the index is required.
As an index is being rebuilt, it uses a segment which is defined as a temporarysegment for the rebuild. Once this segment is fully populated, the allocationof the old index is set to temporary and the populated temporary segment isredefined as a permanent segment with the index name.
Now if the storage clause (next extent for example) for the existing index is setto a very high number (64MB or so) and you don't specify a storage clause withthe rebuild command Oracle will use the storage clause of the existing index toallocate the space for the temporary segments.
This will allocate a lot of (unneeded) space and so you will run into the ora-1652.
可以檢查索引storageclause的配置,看這些值是否合適。
/* Formatted on 2011/8/3 12:27:36(QP5 v5.163.1008.3004) */
SELECT OWNER,
INDEX_NAME,
TABLESPACE_NAME,
INITIAL_EXTENT,
NEXT_EXTENT,
MIN_EXTENTS,
MAX_EXTENTS,
PCT_INCREASE
FROM dba_indexes;