This code for DBAs provides a way to proactively indicate how much total logical disk space is available for tablespaces using the autoextend feature of Oracle on its datafiles. The resulting report sums bytes by tablespace. The output of this code can be used as a stand-alone report or (without headings) the output can be manipulated within a UNIX shell script to capture high percent usage or low available space by tablespace and send an alert by various means.
When autoextend is set, tablespace monitor scripts need to account for the sum of all MAXBYTES of the datafiles of each tablespace, not the current space usage and freespace. The output of this script can be manipulated with UNIX to look for high percent usage to truly know when a datafile is needed based on the maximum size of the tablespace's datafile after it is fully autoextended. The code has been tested on Oracle 8.1.x.
rem * TBSP_monitor.sql rem * rem * This script reports on the allocated space in each tablespace, the rem * amount of free space for each tablespace, and percentage of allocated rem * space that is used. spool /sys/dba/controlm/scripts/TBSP_monitor.lst set sqlcase mixed set pause off set pagesize 0 set echo off set feedback off set linesize 90 ttitle off rem col value NEW_VALUE xdbname noprint format a1 trunc rem select value from v$parameter rem where name='db_name'; rem ttitle center 'Free Space by Tablespace Report' skip 1 - rem center 'Database Instance: 'xdbname
col tablespace_name heading 'Tablespace' form A20 col sum(b.maxbytes) heading '# Bytes' form 999,999,999,990 col (sum(b.maxbytes)-sum(nvl(b.bytes,0))) heading '# Free' form 999,999,999,990 col sum(nvl(b.bytes,0)) heading '# Used' form 999,999,999,990 col (sum(nvl(b.bytes,0))/(sum(nvl(b.maxbytes,1))))*100 heading '% Used' form 990 select b.tablespace_name,sum(b.maxbytes), (sum(b.maxbytes) - sum(nvl(b.bytes,0))), sum(nvl(b.bytes,0)), (sum(nvl(b.bytes,0))/(sum(nvl(b.maxbytes,1))))*100 from sys.dba_data_files b where tablespace_name not in ('RBS') group by b.tablespace_name order by b.tablespace_name; spool off exit rem * rem * End of TBSP_monitor.sql
For More Information
- Feedback: E-mail the editor with your thoughts about this tip.
- More tips: Hundreds of free Oracle tips and scripts.
- Tip contest: 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 the Experts: Our SQL, database design, Oracle, SQL Server, DB2, metadata, and data warehousing gurus are waiting to answer your toughest questions.
- Forums: Ask your technical Oracle questions--or help out your peers by answering them--in our active forums.
- Best Web Links: Oracle tips, tutorials, and scripts from around the Web.
This was first published in December 2002