Home > Oracle Database / Applications Tips > Oracle database administrator > Unix script to gather tablespace information
Oracle Tips:
EMAIL THIS
 TIPS & NEWSLETTERS TOPICS 

ORACLE DATABASE ADMINISTRATOR

Unix script to gather tablespace information


Robert Hanrahan
09.04.2002
Rating: --- (out of 5)


Digg This!    StumbleUpon Toolbar StumbleUpon    Bookmark with Delicious Del.icio.us   


This UNIX script is used to gather tablespace information: space, used_space, fragmentation, and more. To use it, place it into your $HOME/bin so you can launch it wherever you are.

#!/bin/csh -f
# this script was made to view a tablespace view, fragmentation, free space
# usage = space DB_NAME (ORACLE_SID)

setenv ORACLE_SID $1
setenv LOG tbsp_frag`date "+%d-%m-%Y"`.$ORACLE_SID.txt
sqlplus internal <<EOF
spool $LOG
column tablespace_name format a16
column files           heading "no|file" format 9999
column total_kb        heading "total|KB" format 99,999,999
column free_kb         heading "free|KB" format 99,999,999 print
column fragments       heading "no|frags" format 9999
column max_frag        heading "lrgst|frag" format 9,999,999
column min_frag        heading "smlst|frag" format 9,999,999
column pct_used        heading "PCT|Used" format 999
column lfi             heading "FSFI" format 999 noprint
column tfi             heading "TFI"  format 999 noprint
column used_kb         heading "Used|KB" format 99,999,999 noprint

break on report
compute sum of files on report
compute sum of total_kb on report
compute sum of free_kb on report
compute sum of used_kb on report

   select a.tablespace_name tablespace_name,
          round(a.total_bytes/1024)     total_KB,
          a.no_of_files                 files,
          round(b.free_bytes/1024)      free_KB,
          round((a.total_bytes-b.free_bytes)/1024) used_kb,
          b.fragments                   ,
          round(b.max_frag/1024)        max_frag,
          round(b.min_frag/1024)             min_frag,
          round((a.total_bytes-b.free_bytes)*100/a.total_bytes) pct_used,
          a.lfi,c.tfi
     from (select tablespace_name,
                  sum(bytes) total_bytes,
                  count(bytes) no_of_files,
                  sqrt(max(blocks)/sum(blocks))*
                      (100/sqrt(sqrt(count(blocks)))) lfi
             from sys.dba_data_files
            group by tablespace_name) a,
          (select tablespace_name,
                  sum(bytes) free_bytes,
                  count(bytes) fragments,
                  max(bytes)   max_frag,
                  min(bytes)   min_frag
            from sys.dba_free_space
           group by tablespace_name) b,  
           (select tablespace_name,avg(extents) avg_ext,max(extents) max_ext,
            (1/sqrt(greatest(avg(extents)/5,1))*
            (1/sqrt(greatest(max(extents)/10,1))))*100 tfi
              from sys.dba_segments
      group by tablespace_name) c
 where a.tablespace_name    =b.tablespace_name(+)
   and c.tablespace_name(+) =b.tablespace_name;

spool off
exit
EOF

For More Information

  • What do you think about this tip? E-mail the editor at tdichiara@techtarget.com with your feedback.
  • The Best Oracle Web Links: tips, tutorials, scripts, and more.
  • Have an Oracle tip to offer your fellow DBAs and developers? The best tips submitted will receive a cool prize--submit your tip today!
  • Ask your technical Oracle questions--or help out your peers by answering them--in our live discussion forums.
  • Check out our Ask the Experts feature: Our SQL, database design, Oracle, SQL Server, DB2, metadata, and data warehousing gurus are waiting to answer your toughest questions.

Rate this Tip
To rate tips, you must be a member of SearchOracle.com.
Register now to start rating these tips. Log in if you are already a member.


Submit a Tip




Digg This!    StumbleUpon Toolbar StumbleUpon    Bookmark with Delicious Del.icio.us   



RELATED CONTENT
Oracle database administrator
Understanding SQL string functions
What is the difference between a database engineer, architect and administrator?
Import on one table from dump file
Error during RMAN backup
Can I drop a column in SYS schema?
STATSPACK tool: transaction vs. execution measurement
Should I port from Microsoft Access?
How can I find statistics on total memory usage and database connections?
Installing multiple Oracle homes
Modifying SYS password in a RAC environment

RELATED RESOURCES
2020software.com, trial software downloads for accounting software, ERP software, CRM software and business software systems
Search Bitpipe.com for the latest white papers and business webcasts
Whatis.com, the online computer dictionary

DISCLAIMER: Our Tips Exchange is a forum for you to share technical advice and expertise with your peers and to learn from other enterprise IT professionals. TechTarget provides the infrastructure to facilitate this sharing of information. However, we cannot guarantee the accuracy or validity of the material submitted. You agree that your use of the Ask The Expert services and your reliance on any questions, answers, information or other materials received through this Web site is at your own risk.



Oracle Development Solutions - SQL, J2EE, XML, SOA
HomeNewsTopicsTipsAsk the ExpertsMultimediaWhite PapersProductsBlogs
About Us  |  Contact Us  |  For Advertisers  |  For Business Partners  |  Site Index  |  RSS
SEARCH 
TechTarget provides technology professionals with the information they need to perform their jobs - from developing strategy, to making cost-effective purchase decisions and managing their organizations' technology projects - with its network of technology-specific websites, events and online magazines.

TechTarget Corporate Web Site  |  Media Kits  |  Site Map




All Rights Reserved, Copyright 2003 - 2009, TechTarget | Read our Privacy Policy
  TechTarget - The IT Media ROI Experts