Oracle Primary Key Index – How to Make Usable from Unusable

oracleoracle-12c

I have table where it's primary key index got unusable due to partition merge ( I may have done it wrong).

select INDEX_NAME, STATUS from ALL_INDEXES WHERE TABLE_NAME = TRANSACTION' AND INDEX_NAME = 'PK_TRAN';

Status from above query is N/A (unusable)

Then I tried to drop the index

drop index PK_TRAN;

resulted following error.

SQL Error: ORA-02429: cannot drop index used for enforcement of unique/primary key

Then i tried to drop the constraint

alter table TRANSACTION drop constraint PK_TRAN;

resulted following error,

SQL Error: ORA-02273: this unique/primary key is referenced by some foreign keys

Then i tried to drop the problematic reference constraints

select CONSTRAINT_NAME from all_constraints where constraint_type='R' and r_constraint_name='PK_TRAN';

alter table A drop constraint FK_1;

which resulted following error.

SQL Error: ORA-14650: operation not supported for reference-partitioned tables

How can i make transaction table's pk index valid(usable). Currently operation on this table fails with

ORA-01502: index 'PK_TRAN' or partition of such index is in unusable state

Best Answer

01502, 00000, "index '%s.%s' or partition of such index is in unusable state"

MERGE: 1489 RENUMBERED TO 1502

Cause: An attempt has been made to access an index or index partition that has been marked unusable by a direct load or by a DDL operation.

Action: DROP the specified index, or REBUILD the specified index, or REBUILD the unusable index partition.

Now, you have to rebuild index(es) according to their type, Global or Local.

You can rebuild global index partitions in two ways:

  • Rebuild each partition by issuing the ALTER INDEX REBUILD PARTITION statement (you can run the rebuilds concurrently).

  • Drop the entire global index and re-create it. This method is more efficient because the table is scanned only one time.

    Rebuild local indexes using either ALTER INDEX or ALTER TABLE as follows:

  • ALTER INDEX REBUILD PARTITION/SUBPARTITION

    This statement rebuilds an index partition or subpartition unconditionally.

  • ALTER TABLE MODIFY PARTITION/SUBPARTITION REBUILD UNUSABLE LOCAL INDEXES

    This statement finds all of the unusable indexes for the given table partition or subpartition and rebuilds them. It only rebuilds an index partition if it has been marked UNUSABLE.

  • Documentation:About Rebuilding Index Partitions