How to make index unusable and then rebuilt in index - oracle

I have one function that insert thousands of records into table I want to unusable index at that time and then I am processing on that data data so I want to rebuilt that index again.
Is it possible in Oracle?

alter index idx_name unusable;
alter index idx_name rebuild;
but it is possible that you'll need:
drop index idx_name
create [unique] index idx_name ...

Related

How To Rebuild Index of a specific table in Oracle?

I am wondering how to rebuild an index of specific table.
SELECT 'ALTER INDEX '||OWNER||'.'||INDEX_NAME||' REBUILD;'
FROM DBA_INDEXES
WHERE TABLE_NAME = 'JR_SETTING_D';
After running this code, I have tried to insert values in the table but it keeps telling me that
ORA-01502: index or partition of such index is in usable state tips
I am looking for any way of simply rebuilding the table's indexes that I have mentioned in the where statement of the query.
If index (or its partition) is in unusable state and rebuild doesn't help, I'd suggest you to drop the index, insert data (will be faster as Oracle won't have to maintain the index during insert) and - once you're done - create the index again.

ORA-14287 Rebuilding a composite partitioned index on new tablespace

Trying to move composite index partitions from tablespace A to tablespace B.
First I have moved all subpartitions successfully using DDL
ALTER INDEX idx1 REBUILD SUBPARTITION "0001234567889_1" TABLESPACE tablespace1 ONLINE PARALLEL;
dba_ind_subpartitions is now empty on originating tablespace. However indexes in dba_ind_partitions are still pointing to old tablespace. How do i change the tablespace of composite partitioned index?
I have tried rebuilding the indexes unsuccessfull:
SQL> ALTER INDEX idx1 REBUILD PARTITION "0001234567" TABLESPACE tablesspace1 ONLINE PARALLEL
*
ERROR at line 1:
ORA-14287: cannot REBUILD a partition of a composite partitioned index
EDIT:
Is it no possible to rebuild the indexes? Do i need to drop and recreate?
You have composite-partitioned table, so this is normal situation.
https://docs.oracle.com/database/121/VLDBG/GUID-E3F353CB-9748-44D4-B7B1-4BBAAF618D9D.htm
In your case on table or partition level you can modify default attributes.
https://docs.oracle.com/database/121/VLDBG/GUID-C003E6DB-3867-4407-86D2-A51F30AF07CC.htm#VLDBG1177

Rebuild index to a new tablespace, seems to be not working for a pariticular index

I have an index in table_spae_1.
I used the following command to move to table_space_2
alter index my_table_index rebuild tablespace table_space_2 online parallel 63 nologging;
alter index my_table_index noparallel;
alter index my_table_index logging;
But even after executing this the index is still showing to be in table_space_1. (I tried with multiple indexes and all others worked).
The table which contains this index is a very large table(more than 100million records).
What could be the reason?
How can I debug?

Issue in Oracle Insert while Drop index and create after insert records

In oracle i did a insert in to big table contain more than million record.Before insert i drop a index on the table and insert it for a better performance and after insert i create a index for the table .But here is the issue,While creating index on table its shows me Unique constraint error,because it is vioating one of my unique index.Please advice how to proceed furthur.Since i dropped index and insert i am not able to check index while inserting records into table.
Thanks
venkat
The solution would be remove the new offending row and create the index again.You'd be better off if you don't try to insert that row in database.

Oracle database, converting unique index to non-unique one

I understand I can't do this straightforward from studying similar questions on stackoverflow and other sites.
However, I need to do this and I'm willing to go with workarounds.
I tried to create a non-unique index with online and parallel, and then drop the old unique index. However, it fails saying ORA-01408: such column list already indexed.
How to convert an unique index to a non-unique one?
If you don't want to drop the old index before creating the new one, you can cheat a bit by creating the new index with an additional useless column, e.g.:
Assuming a table with the following configuration:
create table mytable (id number);
create unique index myunique on mytable (id);
To convert the index to non unique:
create index temp on mytable (id, 1);
drop index myunique;
create index mynonunique on mytable (id);
drop index temp;
In practice I'm not sure how necessary this is - generally I'd just drop and recreate the index in some low-activity period, preferably take the application down.
Oracle now supports multiple indexes applied to the same set of columns as long as they differ in uniqueness (and/or in some other properties such as bitmap vs. btree and partitioning) and
as long as only one of them is visible.
Therefore you can alter the existing index - changing it to invisible without dropping it and then create a new non-unique index.
CREATE TABLE mytable (id NUMBER);
CREATE UNIQUE INDEX mytable_unique_idx ON mytable(id);
ALTER INDEX mytable_unique_idx INVISIBLE;
CREATE INDEX mytable_nonunique_idx ON mytable(id);
Note that invisible indexes are still maintained by the database and you can change between them by turning one of them to invisible and the second one to visible.

Resources