build list all indexes usage and fragmentation


I search a script for build a list containing all indexes usage and fragmentation.


Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

I wear a lot of hats...

"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.

Guy Hengel [angelIII / a3]Billing EngineerCommented:
I suggest you start reading at this page for the index fragmentation stuff, which is not a "simple" query, but rather guidelines:

about the used (unused) indexes:
below the part that I am using from there
 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;
    spool run_monitor.sql

       'alter index '||owner||'.'||index_name||' monitoring usage;'
       owner not in ('SYS','SYSTEM','PERFSTAT')

    spool off;


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
    ---------------         --- ----

Open in new window

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Oracle Database

From novice to tech pro — start learning today.