Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Oracle index fragmentation

Posted on 2015-01-13
9
Medium Priority
?
1,473 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
Nothing ever in the clear!

This technical paper will help you implement VMware’s VM encryption as well as implement Veeam encryption which together will achieve the nothing ever in the clear goal. If a bad guy steals VMs, backups or traffic they get nothing.

 
LVL 14

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 14

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 14

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 23

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

NFR key for Veeam Agent for Linux

Veeam is happy to provide a free NFR license for one year.  It allows for the non‑production use and valid for five workstations and two servers. Veeam Agent for Linux is a simple backup tool for your Linux installations, both on‑premises and in the public cloud.

Question has a verified solution.

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

Backups and Disaster RecoveryIn this post, we’ll look at strategies for backups and disaster recovery.
An alternative to the "For XML" way of pivoting and concatenating result sets into strings, and an easy introduction to "common table expressions" (CTEs). Being someone who is always looking for alternatives to "work your data", I came across this …
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.
This lesson discusses how to use a Mainform + Subforms in Microsoft Access to find and enter data for payments on orders. The sample data comes from a custom shop that builds and sells movable storage structures that are delivered to your property. …

618 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