?
Solved

Oracle index fragmentation

Posted on 2015-01-13
9
Medium Priority
?
1,376 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 3
  • 2
  • +1
9 Comments
 
LVL 35

Assisted Solution

by:johnsone
johnsone earned 400 total points
ID: 40546368
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
ID: 40546384
Why REBUILD and not SHRINK or COALESCE clause?
0
 
LVL 35

Expert Comment

by:johnsone
ID: 40546394
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
Get MySQL database support online, now!

At Percona’s web store you can order your MySQL database support needs in minutes. No hassles, no fuss, just pick and click. Pay online with a credit card.

 
LVL 13

Accepted Solution

by:
Alexander Eßer [Alex140181] earned 1000 total points
ID: 40546434
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
 

Author Comment

by:ralph_rea
ID: 40546464
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]
ID: 40546491
0
 

Author Comment

by:ralph_rea
ID: 40546597
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]
ID: 40546669
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 600 total points
ID: 40547011
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

Setting up LaraDock for Laravel

Learn how to set up LaraDock in a Laravel project - LaraDock gives us an easy way to run a Laravel application using Docker in a single command.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

It is possible to export the data of a SQL Table in SSMS and generate INSERT statements. It's neatly tucked away in the generate scripts option of a database.
Backups and Disaster RecoveryIn this post, we’ll look at strategies for backups and disaster recovery.
Via a live example, show how to take different types of Oracle backups using RMAN.
In this video, Percona Solution Engineer Dimitri Vanoverbeke discusses why you want to use at least three nodes in a database cluster. To discuss how Percona Consulting can help with your design and architecture needs for your database and infras…
Suggested Courses

764 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