線上重建索引 (alter index index_name rebuild online)雖然延長了索引重建的時間,卻也賦予了我們線上重建索引,提高資料可用性的能力。如果在聯機重建索引的過程中出現錯誤,如使用者終止,網路中斷等,那麼當我們再次重建索引時,有可能會產生ORA-08104錯誤。這是由於先前的操作痕迹沒有清除而造成的。
線上重建索引的過程中,Oracle資料庫會修改資料字典表,並產生中間表(IOT)來記錄索引重建期間發生的dml操作。如果重建過程異常中斷,smon進程會清理重建痕迹,但是如果系統非常繁忙導致smon應接不暇或者dml操作過多導致smon無法擷取相關表上的鎖,從而無法清理重建痕迹,當我們再次重建索引時,就會產生ora-08104錯誤。
下面我們構造一個ora-08104錯誤
--session 1
SQL> alter index ind1 rebuild online;
--session 2
SQL> update tab1 set rn = rn+1;
--session 1 網路故障,斷線
--session 2
SQL> update tab1 set rn = rn+1;
已更新499999行。
SQL> COMMIT;
--session 3
SQL> alter index ind1 rebuild online;
alter index ind1 rebuild online
*
第 1 行出現錯誤:
ORA-08104: 該索引對象 87859 正在被聯機建立或重建
要解決ora-08104錯誤,就要清除重建痕迹,總結方法如下:
- ONLINE_INDEX_CLEAN Function
This function performs a manual cleanup of failed or interrupted online index builds or rebuilds. This action is also performed periodically by SMON, regardless of user-initiated cleanup.
This function returns TRUE if all indexes specified were cleaned up and FALSE if one or more indexes could not be cleaned up.
Syntax
DBMS_REPAIR.ONLINE_INDEX_CLEAN ( object_id IN BINARY_INTEGER DEFAULT ALL_INDEX_ID, wait_for_lock IN BINARY_INTEGER DEFAULT LOCK_WAIT) RETURN BOOLEAN;
Parameters
Table 79-8 ONLINE_INDEX_CLEAN Function Parameters
| Parameter |
Description |
|
object_id
|
Object id of index to be cleaned up. The default cleans up all object ids that qualify. |
|
wait_for_lock
|
This parameter specifies whether to try getting DML locks on underlying table [[sub]partition] object. The default retries up to an internal retry limit, after which the lock get will give up. If LOCK_NOWAIT is specified, then the lock get does not retry. |
declare
isclean boolean;
begin
isclean :=false;
while isclean=false
loop
isclean := DBMS_REPAIR.ONLINE_INDEX_CLEAN(dbms_repair.all_index_id,dbms_repair.lock_wait);
dbms_lock.sleep(10);
end loop;
10 end;
11 /
PL/SQL 過程已成功完成。
更多詳情見請繼續閱讀下一頁的精彩內容:
ORA-01172、ORA-01151錯誤處理
ORA-00600 [2662]錯誤解決
ORA-01078 和 LRM-00109 報錯解決方案
ORA-00471 處理方法筆記
ORA-00314,redolog 損壞,或丟失處理方法
ORA-00257 歸檔日誌過大導致無法儲存的解決辦法