Oracle Script: fix the index with status unusable

Source: Internet
Author: User

ORA-01502: index 'xxx. xxxx' or partition of such index is in unusable state. Solution: Log On With DBA and run the following script.

  1. -- Log On with the DBA permission and execute
  2. -- Fix all indexes in the UNUSABLE status and rebuild them.
  3. Declare
  4. -- Cursor pointing to the index of all UNUSABLE states
  5. CursorCIs
  6. SelectIndex_name, owner
  7. FromDba_indexes
  8. WhereStatus ='Unusable';
  9. Owner dba_indexes.owner % type;
  10. Index_name dba_indexes.index_name % type;
  11. Begin
  12. OpenC;
  13. Loop
  14. FetchCIntoIndex_name, owner;
  15. ExitWhenC % notfound;
  16. ExecuteImmediate'Alter Index'| Owner |'.'| Index_name |'Rebuilt';
  17. EndLoop;
  18. CloseC;
  19. End;

Thought 1: Why does a normal operation cause an index to be unusable?

Thinking 2: how to solve this problem without logging on to the DBA? (I tried to get all the indexes of the current user from the user_indexes table, but they cannot be edited)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

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.