天天看點

建立index 使用Online導緻的問題

在本地的測試庫中,本來空間就不足,結果建立了一個表有600多萬條記錄,想建立一個index. 實體段有340多M.

臨時段大小有100M,結果想建立一個索引,總是報臨時表空間不足的錯誤。

[ora11g@rac1 test]$ ksh test.sh "create unique index t_pk on t(object_id) tablespace pool_data nologging online;"

create unique index t_pk on t(object_id) tablespace pool_data nologging online

                            *

ERROR at line 1:

ORA-01652: unable to extend temp segment by 128 in tablespace TEMPTS1

排除了索引所在的表空間不足的問題,實時監控了一下,發現确實臨時表空間使用率在瞬間飙到100%,然後就報了ORA-01652的錯誤。

在嘗試各種方法之後,先擴大臨時段再次嘗試。

alter database tempfile '/u03/ora11g/oradata/TEST01/temp01.dbf' resize 200M;

結果再次嘗試的時候,就有了如下的錯誤。

ORA-00603: ORACLE server session terminated by fatal error

ORA-01114: IO error writing block to file  (block # )

ORA-01114: IO error writing block to file 201 (block # 15439)

ORA-27072: File I/O error

Additional information: 4

Additional information: 15439

Additional information: 4096

Process ID: 5683

Session ID: 18 Serial number: 103

Elapsed: 00:00:21.11

ERROR:

ORA-03114: not connected to ORACLE

一看就有些崩潰了,以為資料庫又挂了。一看程序,還在,還能連接配接。

[ora11g@rac1 dbm_lite]$ ps -ef|grep smon

ora11g    2357     1  0 05:32 ?        00:00:01 ora_smon_TEST01

ora11g    5746  5327  0 06:27 pts/0    00:00:00 grep smon

檢視alert日志。

Fri Jun 06 06:26:14 2014

alter database tempfile '/u03/ora11g/oradata/TEST01/temp01.dbf' resize 200M

Completed: alter database tempfile '/u03/ora11g/oradata/TEST01/temp01.dbf' resize 200M

Fri Jun 06 06:26:39 2014

online index (re)build cleanup: objn=15331 maxretry=2000 forever=0

Fri Jun 06 06:26:57 2014

Non critical error OR

那就再次嘗試建立,結果錯誤接二連三。

再次建立,提示索引已經存在了。 

create unique index t_pk on t(object_id) tablespace pool_data nologging

                    *

ORA-00955: name is already used by an existing object

那我删除重建呢。

drop index t_pk

           *

ORA-08104: this index object 15334 is being online built or rebuilt

試試force選項。

drop index t_pk force

*

ORA-29862: cannot specify FORCE option for dropping non-domain index

檢視Index的狀态,顯示是valid

********** INDEX DETAILS INFO *****************

INDEX_NAME                     TABLESPACE INDEX_TYPE UNIQUENES PAR COLUMN_LIST                    TABLE_TYPE STATUS   NUM_ROWS LAST_ANAL G

------------------------------ ---------- ---------- --------- --- ------------------------------ ---------- ------ ---------- --------- -

T_PK                           POOL_DATA  NORMAL     UNIQUE    NO  OBJECT_ID                      TABLE      VALID                       N

TABLE_NAME                     INDEX_NAME                     CLUSTERING_FACTOR     BLOCKS   NUM_ROWS

------------------------------ ------------------------------ ----------------- ---------- ----------

T                              T_PK                                                  39174    6856704

那我再次rebuild 可以嗎?

alter index t_pk rebuild parallel 4

無奈,總不能一直等着吧。而且過了好一會兒,也不見有進展。

如果在生産環境中,那絕對算是一次事故。在早期版本中,可能隻有重新開機,讓smon來做清理了。

不知道從10g還是11g開始,有dbms_repair包,裡面還包括了一個蠻實用的方法。可以解決這個問題。

SQL> declare

  2  isClean boolean;

  3 

  4  begin

  5  isClean := FALSE;

  6  while isClean=FALSE loop

  7  isClean := dbms_repair.online_index_clean(dbms_repair.all_index_id,

  8  dbms_repair.lock_wait);

  9  dbms_lock.sleep(2);

10  end loop;

11  exception

12  when others then

13  RAISE;

14  end;

15  /

PL/SQL procedure successfully completed.

運作成功後,再次嘗試。

ORA-01418: specified index does not exist

這終于是我期望的結果了,看來在生産中,index的online rebuild也要慎重使用。