[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More
Experts Exchange Solution brought to you by
"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.
Finding unused indexes on Oracle
One of the great features of Oracleis the ability to easily locate and remove unused indexes. When an index is not used by SQL queries with the cost-based optimizer, the unused indexes waste space and cause INSERT statements to run slower.
When you issue the alter index <index_name> monitoring usage command, Oracle places an entry in the v$object_usage view so you can see if the index is used. This is just a bit-flag that is set to “1” when the index is accessed by any SQL statement.
Here is a simple SQL*Plus script to track all index usage in all Oracle schemas:
set pages 999;
set heading off;
'alter index '||owner||'.'||index_name||' monitoring usage;'
owner not in ('SYS','SYSTEM','PERFSTAT')
Next, we wait until a significant amount of SQL has executed on our database, and then query the new v$object_usage view:
Here we see that v$object_usage has a single column called used, which will be set to YES or NO. Sadly, this will not tell you how many times the index has been used, but this tool is useful for investigating unused indexes.
INDEX_NAME MON USED
--------------- --- ----
CUSTOMER_LAST_NAME_IDX YES NO
Open in new window
Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.
From novice to tech pro — start learning today.
Premium members can enroll in this course at no extra cost.