Solved

Oracle index fragmentation

Posted on 2015-01-13
9
900 Views
Last Modified: 2015-01-18
Hi experts,
my Oracle DB version is: Oracle Database 11g Enterprise Edition Release 11.2.0.3.0 - 64bit Production

I've 150 indexes with high fragmentation and now I'd like to remove or to reduce index fragmentation (Shrinking Indexes), but I need that this operation be done completely online.

Which SQL script I can use to reduce the index defragmentation?

Thanks in advance!
0
Comment
Question by:ralph_rea
  • 3
  • 3
  • 2
  • +1
9 Comments
 
LVL 34

Assisted Solution

by:johnsone
johnsone earned 100 total points
Comment Utility
The command that you would use to rebuild an index would be:

ALTER INDEX ... REBUILD ONLINE ...;

There are restrictions on rebuilding an index and on rebuilding an index online.  Those are outlined here -> http://docs.oracle.com/cd/E11882_01/server.112/e41084/statements_1010.htm#SQLRF00805
0
 

Author Comment

by:ralph_rea
Comment Utility
Why REBUILD and not SHRINK or COALESCE clause?
0
 
LVL 34

Expert Comment

by:johnsone
Comment Utility
My understanding of shrink is that it would only work with completely empty blocks.  A rebuild would also reclaim space in blocks that still have data in them.  With a table it isn't as much of an issue because partial blocks could be reused, but that is not the case with index blocks (they must be completely empty before they go back on the free list).
0
 
LVL 13

Accepted Solution

by:
Alexander Eßer [Alex140181] earned 250 total points
Comment Utility
I found a quite useful explanation here:
https://richardfoote.wordpress.com/2008/02/08/index-rebuild-vs-coalesce-vs-shrink-space-pigs-3-different-ones/

and the comparison: https://richardfoote.files.wordpress.com/2007/12/when-to-use-rebuild-vs-coalesce-vs-shrink-space.pdf

Rebuild on the other hand will take an entirely different approach. It will (generally) read the entire existing index structure and will build a brand new, bright and shining index segment.  As part of this process, it will rebuild the entire index, it has no choice (assuming the index isn’t partitioned, but that’s another story) and will rebuild the 90% of the index that was actually perfect to begin with. Rebuilding 90% of something that doesn’t need rebuilding doesn’t sound particularly efficient and indeed it isn’t. As a result, the index rebuild will use substantially more resources and generate substantially more redo than an equivalent Coalesce (or Shrink Space).
0
How to improve team productivity

Quip adds documents, spreadsheets, and tasklists to your Slack experience
- Elevate ideas to Quip docs
- Share Quip docs in Slack
- Get notified of changes to your docs
- Available on iOS/Android/Desktop/Web
- Online/Offline

 

Author Comment

by:ralph_rea
Comment Utility
Ok, Could I know how much redo will be generated as a result of this Coalesce or Shrink Space?
0
 
LVL 13

Expert Comment

by:Alexander Eßer [Alex140181]
Comment Utility
0
 

Author Comment

by:ralph_rea
Comment Utility
To avoid to generate redo, I thought to run this script for each index:

ALTER INDEX <myindex> NOLOGGING;
ALTER INDEX <myindex> SHRINK SPACE COMPACT;
ALTER INDEX <myindex> SHRINK SPACE CASCADE;
ALTER INDEX <myindex> LOGGING;

What do you think?
0
 
LVL 13

Expert Comment

by:Alexander Eßer [Alex140181]
Comment Utility
If you decide to perform this on productive/live site, I'd suggest you'd better take a backup before and after that operation!
The NOLOGGING options is a very powerful "switch" considering time/performance issues, BUT it may be quite "harmful" within productive environments, SO think twice before you use it ;-)
0
 
LVL 22

Assisted Solution

by:Steve Wales
Steve Wales earned 150 total points
Comment Utility
The other thing to consider is - does your index really need to be rebuilt ?

The latest documents from Oracle Support on that topic are worth a read:

Index Rebuild, the Need vs the Implications (Doc ID 989093.1)
Script to investigate a b-tree index structure (Doc ID 989186.1)
0

Featured Post

Highfive + Dolby Voice = No More Audio Complaints!

Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

Join & Write a Comment

Composite queries are used to retrieve the results from joining multiple queries after applying any filters. UNION, INTERSECT, MINUS, and UNION ALL are some of the operators used to get certain desired results.​
This article describes some very basic things about SQL Server filegroups.
This video shows, step by step, how to configure Oracle Heterogeneous Services via the Generic Gateway Agent in order to make a connection from an Oracle session and access a remote SQL Server database table.
This video shows how to configure and send email from and Oracle database using both UTL_SMTP and UTL_MAIL, as well as comparing UTL_SMTP to a manual SMTP conversation with a mail server.

771 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now