Oracle 指令碼:修複 status 為 unusable 的 index

來源:互聯網
上載者:User

有組態工具使用時, 經常會出現以下錯誤: ORA-01502: index 'xxx.xxxxx' or partition of such index is in unusable state,解決方案為——以 DBA 登入,並運行以下指令碼即可

  1. -- 請以 DBA 許可權登入,並執行   
  2. -- 將所有 UNUSABLE 狀態的 index 修複, rebuild 一下即可   
  3. declare  
  4.   -- 指向所有 UNUSABLE 狀態的 index 的遊標   
  5.   cursor c is   
  6.     select index_name, owner   
  7.     from dba_indexes   
  8.     where status='UNUSABLE';  
  9.     
  10.   owner dba_indexes.owner%type;  
  11.   index_name dba_indexes.index_name%type;  
  12. begin  
  13.   open c;  
  14.   loop   
  15.        fetch c into index_name, owner;   
  16.        exit when c%notfound;  
  17.          
  18.        execute immediate 'alter index ' || owner || '.' || index_name || ' rebuild';  
  19.   end loop;  
  20.   close c;  
  21. end;  

思考1: 為什麼正常的操作會導致某個 index 出現 unusable 的情況?

思考2:怎樣在不登入 DBA 的情況下解決這個問題?(我試了一下從 user_indexes 表裡可以拿到目前使用者所有的 index, 但是無法編輯)

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.