Professional Documents
Culture Documents
In this document, I will demonstrate how to reclaim the unused space using the
segment advisor and manual commands with Oracle 11g. I will use IBM Sterling
Integrator 5 to fill a table called TRANS_DATA that contain a blob column called
DATA_OBJECT.
WF_ID NUMBER
REFERENCE_TABLE VARCHAR2(255)
Using SQL:
from dba_free_space
group by tablespace_name) a,
from dba_data_files
group by tablespace_name) b
where a.tablespace_name(+)=b.tablespace_name
The tablespace called SI51GM has 875MB allocated with 201MB free.
Now let us load this tablespace SI51GM using IBM Sterling Integrator:
Some of the free space was reused and the tablespace has increased to 950MB
Procedure for Sterling Integrator to delete the data from the table
The data was removed from the tables. However, the space is not reclaimed and the
tablespace size has actually increased to 1100MB!!
We are only using about 50MB for this blob column, we use the dbms_lob to find the size of
the binary objects:
We have about 500 MB used between TRANS_DATA table and its LOB segment:
select segment_name,segment_type,tablespace_name,round(bytes/1024/1024) MB
from user_segments where tablespace_name ='SI51GM' order by bytes desc
The Segment Advisor identifies segments that have space available for reclamation.
It performs its analysis by examining usage and growth statistics in the Automatic
Workload Repository (AWR), and by sampling the data in the segment. It is
configured to run during maintenance windows as an automated maintenance task,
and you can also run it on demand (manually). The Segment Advisor automated
maintenance task is known as the Automatic Segment Advisor.
DECLARE
taskname varchar2(100);
taskdesc varchar2(128);
task_id number;
object_id number;
timeLimit varchar2(25);
numDaysToRetain varchar2(25);
objectName varchar2(100);
objectType varchar2(100);
BEGIN
taskname := 'SEGMENTADV_2503141';
taskdesc :='Get shrink advice based on object growth trend';
numDaysToRetain :='30';
dbms_advisor.create_task('Segment Advisor',?,taskname,taskdesc,NULL);
dbms_advisor.create_object(taskname, 'TABLESPACE', 'SI51GM', ' ', ' ',
NULL, object_id);
dbms_advisor.set_task_parameter(taskname, 'RECOMMEND_ALL', 'TRUE');
dbms_advisor.set_task_parameter(taskname, 'DAYS_TO_EXPIRE',
numDaysToRetain);
END;
The segment advisor found 247MB to reclaim from the TRANS_DATA table. Below is
the SQL query to shrink the table:
PL/SQL
begin
EXECUTE IMMEDIATE 'alter table "SI51GM"."TRANS_DATA" shrink space';
end;
We need to run the segment advisor manually to analyze the LOB segment for the
TRANS_DATA table. The following procedures enables you to include the schema
object's dependent objects in the Segment Advisor run. For example, if you select a
table and select the Run Segment Advisor command, Enterprise Manager displays
the table's dependent objects, such as partitions, index segments, LOB segments,
and so on. You can then select dependent objects to include in the run.
To run the Segment Advisor manually with the Segment Advisor Wizard:
1. From the database Home page, under Related Links, click Advisor Central.
2. Follow the wizard steps to schedule the Segment Advisor job, and then click
Submit on the final wizard page.
The Advisor Central page reappears, with the new Segment Advisor job at the
top of the list under the Results heading. The job status is SCHEDULED. (If
you don't see your job, use the search fields above the list to display it.)
3. Check the status of the job. If it is not COMPLETED, click the Refresh
button at the top of the page repeatedly. (Do not use your browser's Refresh
icon.)
When the job status changes to COMPLETED, select the job by clicking in the
Select column, and then click View Result.
SQL Query to list all the lob segments for a given tablespace:
select segment_name,segment_type,tablespace_name, round(bytes/1024/1024) MB
from user_segments where tablespace_name='SI51GM' and
segment_type='LOBSEGMENT' order by bytes desc
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).
Shrinking a LOB segment does generate redo. For example, shrinking a 15GB
LOB will generate approximately 15GB of redo! Make sure you have an
adequate amount of disk space for any archived redo log files before
manually shrinking a LOB segment.
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