Solved

Oracle index fragmentation

Posted on 2015-01-13
9
1,097 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
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 34

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
Space-Age Communications Transitions to DevOps

ViaSat, a global provider of satellite and wireless communications, securely connects businesses, governments, and organizations to the Internet. Learn how ViaSat’s Network Solutions Engineer, drove the transition from a traditional network support to a DevOps-centric model.

 
LVL 13

Accepted Solution

by:
Alexander Eßer [Alex140181] earned 250 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 150 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

Efficient way to get backups off site to Azure

This user guide provides instructions on how to deploy and configure both a StoneFly Scale Out NAS Enterprise Cloud Drive virtual machine and Veeam Cloud Connect in the Microsoft Azure Cloud.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
corrupt Databases 9 65
Syntax Issue with SSIS module 26 103
TSQL Challenge... 7 35
Need help in debugging a UDF results 7 21
I annotated my article on ransomware somewhat extensively, but I keep adding new references and wanted to put a link to the reference library.  Despite all the reference tools I have on hand, it was not easy to find a way to do this easily. I finall…
Never store passwords in plain text or just their hash: it seems a no-brainier, but there are still plenty of people doing that. I present the why and how on this subject, offering my own real life solution that you can implement right away, bringin…
This video shows information on the Oracle Data Dictionary, starting with the Oracle documentation, explaining the different types of Data Dictionary views available by group and permissions as well as giving examples on how to retrieve data from th…
This video shows syntax for various backup options while discussing how the different basic backup types work.  It explains how to take full backups, incremental level 0 backups, incremental level 1 backups in both differential and cumulative mode a…

839 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