Image

CODE DEPOT
APRIL 15, 1996

No. 6: Map a Tablespace's Used and Free Space

This "Code Depot" entry comes from Kevin Loney, the author of two of the first three books from Oracle Press: Oracle DBA Handbook and Oracle: The Complete Reference, Third Edition (with George Koch). See the Osborne/McGraw-Hill Web site at www.osborne.com. for sample chapters from these books and the scripts from the Oracle DBA Handbook.

This is the sixth of Kevin Loney's "10 Scripts Every DBA Should Have." Watch for a complete article on how to use these scripts in a future issue of Oracle Magazine. There are other valuable scripts as well, but these ten--covering backup/recovery, space management, account management, maintenance, and tuning--provide basic guideposts to start from during your administration activities.

Don't leave $ORACLE_HOME without them!

Since DBA_EXTENTS shows the starting block of each extent (the combination of File_ID and Block_ID), plus the length of each extent (the Blocks column), you can map out the allocated space within a given tablespace as a series of consecutive extents. DBA_FREE_SPACE shows the free extents, so the combination of DBA_EXTENTS and DBA_FREE_SPACE produces a map of the used and unused free space within a tablespace. You can use this map of the tablespace's space to determine whether an object has been properly sized or if the tablespace needs to be defragmented.

select Segment_Name, File_Id, Block_Id, Blocks 
 from DBA_EXTENTS 
 where Tablespace_Name = '&&tablespacename' 
 UNION 
select 'Free Space', File_Id, Block_Id, Blocks 
 from DBA_FREE_SPACE 
 where Tablespace_Name = '&&tablespacename' 
 order by 2,3; 


All specific technical questions from users of Oracle supported products should be directed to Oracle's Technical Support Department. Oracle does not provide any warranty as to the accuracy of any information provided through Oracle Magazine Interactive. Oracle shall not be liable for any damages incurred as a result of reliance on any information provided herein.

Copyright © 1994, 1995, 1996 & 1997 Oracle Corporation. All Rights Reserved.




This is a copy of an article published @ http://www.oramag.com/