Disable and later enable all table indexes in Orac

2020-02-24 19:26发布

How would I disable and later enable all indexes in a given schema/database in Oracle?

Note: This is to make sqlldr run faster.

8条回答
Deceive 欺骗
2楼-- · 2020-02-24 19:38

combining 3 answers together: (because a select statement does not execute the DDL)

set pagesize 0

alter session set skip_unusable_indexes = true;
spool c:\temp\disable_indexes.sql
select 'alter index ' || u.index_name || ' unusable;' from user_indexes u;
spool off
@c:\temp\disable_indexes.sql

Do import...

select 'alter index ' || u.index_name || 
' rebuild online;' from user_indexes u;

Note this assumes that the import is going to happen in the same (sqlplus) session.
If you are calling "imp" it will run in a separate session so you would need to use "ALTER SYSTEM" instead of "ALTER SESSION" (and remember to put the parameter back the way you found it.

查看更多
一纸荒年 Trace。
3楼-- · 2020-02-24 19:41

Combining the two answers:

First create sql to make all index unusable:

alter session set skip_unusable_indexes = true;
select 'alter index ' || u.index_name || ' unusable;' from user_indexes u;

Do import...

select 'alter index ' || u.index_name || ' rebuild online;' from user_indexes u;
查看更多
再贱就再见
4楼-- · 2020-02-24 19:53

You should try sqlldr's SKIP_INDEX_MAINTENANCE parameter.

查看更多
神经病院院长
5楼-- · 2020-02-24 19:54

From here: http://forums.oracle.com/forums/thread.jspa?messageID=2354075

alter session set skip_unusable_indexes = true;

alter index your_index unusable;

do import...

alter index your_index rebuild [online];

查看更多
老娘就宠你
6楼-- · 2020-02-24 19:54

If you're on Oracle 11g, you may also want to check out dbms_index_utl.

查看更多
看我几分像从前
7楼-- · 2020-02-24 19:55

If you are using non-parallel direct path loads then consider and benchmark not dropping the indexes at all, particularly if the indexes only cover a minority of the columns. Oracle has a mechanism for efficient maintenance of indexes on direct path loads.

Otherwise, I'd also advise making the indexes unusable instead of dropping them. Less chance of accidentally not recreating an index.

查看更多
登录 后发表回答