Solved

Oracle index fragmentation

Posted on 2015-01-13
9
933 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
 
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
PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

 

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

3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Cassandra Select Query 1 53
Supress rows in SSRS table based on Like or Soundex 2 39
Query Records that don't match 8 34
Oracle 12c database link between pdb not working 20 42
APEX (Application Express) is used to develop a web application from Oracle. SQL Workshop is one of the tools that comes with Oracle APEX to query or modify the database objects or to make any changes to the structure.
From implementing a password expiration date, to datatype conversions and file export options, these are some useful settings I've found in Jasper Server.
This video shows how to set up a shell script to accept a positional parameter when called, pass that to a SQL script, accept the output from the statement back and then manipulate it in the Shell.
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.

911 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

23 Experts available now in Live!

Get 1:1 Help Now