DBA Tips Archive for Oracle
No Title[an error occurred while processing this directive]
by Michael New, MichaelNew@earthlink.net, Gradation LLC
Manually reclaiming unused space in a normal Oracle table is a fairly simple process and can be performed online starting with Oracle 10g R1 as follows:
For example, to reclaim space from the table mytable:
What if, however, the table contains a LOB column that contains significant unused space? Starting with Oracle 10g R2, Oracle provides a solution that allows users to reclaim LOB space (LOB data and LOB index) and that is the topic of this article.
The syntax used to reclaim LOB space is:
Example binary image file to load into BLOB column.
Create example table to store binary images into a LOB column.
Create Oracle sequence to track images.
Create Oracle directory for binary image files.
Create a sample PL/SQL procedure to load images from the file system to a BLOB column.
Run script to load 1,000 images (25MB) to LOB column.
Determine name and size of the LOB column.
Now let's delete all images (BLOBS) and see what the size is after.
Hmmm, so it looks like the images are gone, but the space is still allocated within the LOBSEGMENT (25MB). Ok, so maybe if we insert data back into the table (more importantly, the LOB column), that space will be recycled.
Ok, so I was wrong. The LOB space did not get recycled with the new data. Let's now pull out the big guns and manually shrink the LOB segment to free up the space immediately.
Now that looks better!
The alter table <table_name> shrink space statement was introduced in Oracle 10g R1. The ability to extend the SHRINK SPACE command to LOBs was introduced in Oracle 10g R2 - the focus of this article. This new feature allows users to remove the deleted and free space altogether from a LOB segment and LOB index.
The LOB segment must reside in an ASSM tablespace.
Row movement on a table is only required if you are moving rows from the table itself. It is not required if all you are doing is shrinking its LOB segment(s).
Excessive Redo Generated
Shrinking a LOB segment does generate redo. For example, shrinking a 36GB LOB will generate approximately 36GB of redo. Make certain you have an adequate amount of disk space for any archived redo log files before manually shrinking a LOB segment.
The CASCADE Option
The alter table <table_name> shrink space statement has an optional CASCADE clause that shrinks all dependent objects (including LOBS) along with the table data itself. For example:
With Oracle 10g R1, when shrinking a table, the CASCADE option DOES NOT shrink LOB segments for that table.
With Oracle 10g R2 and higher, when shrinking a table, the CASCADE option DOES shrink all LOB segments (and indexes) for that table.
Jeffrey Hunter is an Oracle Certified Professional, Java Development Certified Professional, Author, and an Oracle ACE. Jeff currently works as a Senior Database Administrator for The DBA Zone, Inc. located in Pittsburgh, Pennsylvania. His work includes advanced performance tuning, Java and PL/SQL programming, developing high availability solutions, capacity planning, database security, and physical / logical database design in a UNIX / Linux server environment. Jeff's other interests include mathematical encryption theory, tutoring advanced mathematics, programming language processors (compilers and interpreters) in Java and C, LDAP, writing web-based database administration tools, and of course Linux. He has been a Sr. Database Administrator and Software Engineer for over 20 years and maintains his own website site at: http://www.iDevelopment.info. Jeff graduated from Stanislaus State University in Turlock, California, with a Bachelor's degree in Computer Science and Mathematics.
Copyright (c) 1998-2017 Jeffrey M. Hunter. All rights reserved.
All articles, scripts and material located at the Internet address of http://www.idevelopment.info is the copyright of Jeffrey M. Hunter and is protected under copyright laws of the United States. This document may not be hosted on any other site without my express, prior, written permission. Application to host any of the material elsewhere can be made by contacting me at email@example.com.
I have made every effort and taken great care in making sure that the material included on my web site is technically accurate, but I disclaim any and all responsibility for any loss, damage or destruction of data or any other property which may arise from relying on it. I will in no case be liable for any monetary damages arising from such loss, damage or destruction.
Last modified on
Thursday, 15-Mar-2012 13:53:39 EDT
Page Count: 105030