Call now: 252-767-6166  
Oracle Training Oracle Support Development Oracle Apps

Free Oracle Tips

HTML Text

 Home
 E-mail Us
 Oracle Articles



 Oracle Training
 Oracle News

 Oracle Forum
 Class Catalog


 Our Staff
 Our Prices
 Help Wanted!

 Remote DBA
 Oracle Tuning
 Emergency 911
 RAC Support
 Apps Support
 Analysis
 Design
 Implementation
 Oracle Support


 SQL Tuning
 Security

 UNIX
 Oracle UNIX
 Linux
 Oracle Linux
 Monitoring
 Remote help

 Remote plans
 Remote
services
 Oracle C++
 Oracle Java
 Apache
 JDeveloper
 App Server

 Applications
 Oracle Forms
 Oracle Portal
 11i Upgrades
 SQL Server
 Oracle Concepts
 HTML-DB Tips
 Software Help

 Remote Help  
 Development  

 Implementation


 Financials Training
 Oracle 11i
 Oracle Apps 11i
 Oracle Workflow
 Oracle AR 11i Class
 Oracle AP 11i class
 Oracle GL 11i class
 Oracle HR 11i class
 Oracle FA 11i class
 11i Project Mgt
 11i procurement
 11i collections


 Oracle Posters
 Oracle Books

 Oracle Tuning Book
 Oracle RAC Book
 Oracle Security
 Easy Oracle Books
 Oracle Scripts
 SQL Server DBA
 SQL Design Patterns
 WISE
 Excel-DB   


 BC Oracle News


 Rednecks!
 Dress code
 Arabian Stallion

 Burleson Arabians
 Guide Horses
 Don Burleson Blog
 Golf & Travel


 Privacy Policy
 

 

 

 
 

Oracle table shrink space commands

Oracle Tips by Burleson Consulting


 

Oracle has several commands to reclaim unused disk space for objects (tables and indexes).  Using the "alter table xxx shrink space compact" command also has the benefit of making full-table scans run faster, as less block accesses are required.  With standard Oracle tables, you can reclaim space with the "alter table shrink space" command:

SQL> alter table mytable enable row movement;
Table altered

SQL> alter table mytable shrink space;
Table altered

Finding tables and indexes for shrinking

 

The Oracle 10g segment advisor will recommend tables that will benefit from shrinking and indexes that require rebuilding (to reclaim space).  You can see the recommendations by querying  dba_advisor_findings.  See my notes on the segment advisor here:

 

Alter table shrink space compact

 

With the introduction of the alter table xxx shrink space compact syntax, the DBA gets a powerful tool for effective and easy database space management. However, the DBA needs to know what data segments experience high space waste in order to reclaim free space to the database and shrink segments. The awr_list_seg_block_space.sql script below reports percentages of free space for data segments:

 

<      awr_list_seg_block_space.sql

 

-- *************************************************

-- Copyright © 2005 by Rampant TechPress

-- This script is free for non-commercial purposes

-- with no warranties.  Use at your own risk.

--

-- To license this script for a commercial purpose,

-- contact info@rampant.cc

-- *************************************************

 

drop type BlckFreeSpaceSet;

drop type BlckFreeSpace;

 

create type BlckFreeSpace as object

(

 seg_owner varchar2(30),

 seg_type varchar2(30),

 seg_name varchar2(100),

 fs1 number,

 fs2 number,

 fs3 number,

 fs4 number,

 fb  number

 );

 

create type BlckFreeSpaceSet as table of  BlckFreeSpace;

 

create or replace function BlckFreeSpaceFunc (seg_owner IN varchar2, seg_type in varchar2 default null) return BlckFreeSpaceSet

pipelined

is

   outRec BlckFreeSpace := BlckFreeSpace(null,null,null,null,null,null,null,null);

   fs1_b number;

   fs2_b number;

   fs3_b number;

   fs4_b number;

   fs1_bl number;

   fs2_bl number;

   fs3_bl number;

   fs4_bl number;

   fulb number;

   fulbl number;

   u_b number;

   u_bl number;

begin

  for rec in (select s.owner,s.segment_name,s.segment_type from dba_segments s where owner = seg_owner and segment_type = nvl(seg_type,segment_type) )

SEE CODE DEPOT FOR FULL SCRIPT

    dbms_space.space_usage(

      segment_owner      => rec.owner,

      segment_name       => rec.segment_name,

      segment_type       => rec.segment_type,

      fs1_bytes          => fs1_b,

      fs1_blocks         => fs1_bl,

      fs2_bytes          => fs2_b,

      fs2_blocks         => fs2_bl,

      fs3_bytes          => fs3_b,

      fs3_blocks         => fs3_bl,

      fs4_bytes          => fs4_b,

      fs4_blocks         => fs4_bl,

      full_bytes         => fulb,

      full_blocks        => fulbl,

      unformatted_blocks => u_bl,

      unformatted_bytes  => u_b

   );

 

   outRec.seg_owner := rec.owner;

   outRec.seg_type := rec.segment_type;

   outRec.seg_name := rec.segment_name;

  

   outRec.fs1 := fs1_bl;

   outRec.fs2 := fs2_bl;

   outRec.fs3 := fs3_bl;

   outRec.fs4 := fs4_bl;

   outRec.fb  := fulbl;

 

   Pipe Row (outRec);

 

  end loop;

  return;

end;

/

 

If you like Oracle tuning, you may enjoy the new book "Oracle Tuning: The Definitive Reference", over 900 pages of BC's favorite tuning tips & scripts. 

You can buy it direct from the publisher for 30%-off and get instant access to the code depot of Oracle tuning scripts.


    Need an Oracle Health Check?
  • Do you have bad performance after an upgrade?
     
  • Need to certify that your database follows best practices?

BC Oracle performance gurus can quickly certify every aspect of your Oracle database and provide a complete verification that your database is fully optimized.

 

 

 

 
 
 

Oracle performance tuning book

 

 

Oracle performance tuning software

 
Oracle performance tuning software
 
SearchOracle web site
 
Oracle performance Tuning 10g reference poster
 
Oracle performance tuning webcast
 
Oracle training in Linux commands
 
Oracle training Excel
 
Oracle training & performance tuning books
 

 

Note: This Oracle documentation was created as a support and Oracle training reference for use by our DBA performance tuning consulting professionals.  Feel free to ask questions on our Oracle forum.

Verify experience! Anyone considering using the services of an Oracle support expert should independently investigate their credentials and experience, and not rely on advertisements and self-proclaimed expertise. All legitimate Oracle experts publish their Oracle qualifications.

Errata?  Oracle technology is changing and we strive to update our BC Oracle support information.  If you find an error or have a suggestion for improving our content, we would appreciate your feedback.  Just  e-mail:  and include the URL for the page.
 
 


Burleson Consulting

The Oracle of database support


 

Copyright © 1996 -  2007 by Burleson Enterprises, Inc. All rights reserved.

Oracle® is the registered trademark of Oracle Corporation.


Hit Counter