0% found this document useful (0 votes)
449 views4 pages

Tablespace Growth Report

This document provides a PL/SQL procedure and SQL queries to generate tablespace growth reports from the database historical space usage data. The reports show the allocated size, current used size, previously used size, and variance for different tablespaces over time. Instructions are also included on how to email the reports as attachments for analysis of tablespace growth trends and calculating how many days the available free space in each tablespace can be sustained.

Uploaded by

JP Vijaykumar
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
449 views4 pages

Tablespace Growth Report

This document provides a PL/SQL procedure and SQL queries to generate tablespace growth reports from the database historical space usage data. The reports show the allocated size, current used size, previously used size, and variance for different tablespaces over time. Instructions are also included on how to email the reports as attachments for analysis of tablespace growth trends and calculating how many days the available free space in each tablespace can be sustained.

Uploaded by

JP Vijaykumar
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 4

TABLESPACE GROWTH REPORT Author JP Vijaykumar Date Sept 8 2013 Modified Sept 14 2013 Modified Dec 8 2013 /* The

period range for this report is dependent on the snapshot retention period set for the db. */ --TABLESPACE GROWTH REPORT(USING PL/SQL PROCEDURE) set serverout on size 1000000 timing on declare v_num number; begin dbms_output.put_line('DB_NAME,RUN_DATE,TS_NAME,ALLOC_GB,CURR_USED_GB,PREV_US ED_GB,VARIANCE,%CHANGE'); for c1 in (select name,tablespace_name from dba_tablespaces,v$database where (tablespace_name like '%DATA%' or tablespace_name like '%INDEX%' ) order by tablespace_name) loop v_num :=0; for c2 in ( select ss.run_time,ts.name,round(su.tablespace_size*dt.block_size/1024/1024/ 1024,2) alloc_size_gb, round(su.tablespace_usedsize*dt.block_size/1024/1024/1024,2) used_size_gb from dba_hist_tbspc_space_usage su, (select trunc(BEGIN_INTERVAL_TIME) run_time,max(snap_id) snap_id from dba_hi st_snapshot group by trunc(BEGIN_INTERVAL_TIME) ) ss, v$tablespace ts, dba_tablespaces dt where su.snap_id = ss.snap_id and su.tablespace_id = ts.ts# and ts.name = c1.tablespace_name and ts.name = dt.tablespace_name order by 1) loop if (v_num = 0) then dbms_output.put_line(c1.name||','||c2.run_time||' ,'||c2.name||', '||c2.alloc _size_gb||', '||c2.used_size_gb||' ,'||v_num||','||c2.used_size_gb||', 0 %'); elsif (v_num < c2.used_size_gb) then dbms_output.put_line(c1.name||','||c2.run_time||', '||c2.name||', '||c2.alloc _size_gb||' ,'||c2.used_size_gb||' ,'||v_num||','||(c2.used_size_gb - v_num)||', '|| round((c2.used_size_gb - v_num)*100/v_num,2)||' % '); elsif (v_num > c2.used_size_gb) then dbms_output.put_line(c1.name||','||c2.run_time||', '||c2.name||', '||c2.alloc _size_gb||', '||c2.used_size_gb||', '||v_num||','||(c2.used_size_gb - v_num)||', -'|| round((v_num - c2.used_size_gb)*100/v_num,2)||' % '); else dbms_output.put_line(c1.name||','||c2.run_time||' ,'||c2.name||' ,'||c2.alloc _size_gb||' ,'||c2.used_size_gb||','||v_num||',0, 0 %'); end if; v_num:=c2.used_size_gb; end loop; end loop; end;

--TABLESPACE GROWTH REPORT(USING SQLPLUS) set linesize 120 column name format a15 column variance format a20 alter session set nls_date_format='yyyy-mm-dd'; with t as ( select ss.run_time,ts.name,round(su.tablespace_size*dt.block_size/1024/1024/1024 ,2) alloc_size_gb, round(su.tablespace_usedsize*dt.block_size/1024/1024/1024,2) used_size_gb from dba_hist_tbspc_space_usage su, (select trunc(BEGIN_INTERVAL_TIME) run_time,max(snap_id) snap_id from dba_hist_s napshot group by trunc(BEGIN_INTERVAL_TIME) ) ss, v$tablespace ts, dba_tablespaces dt where su.snap_id = ss.snap_id and su.tablespace_id = ts.ts# and ts.name =upper('&TABLESPACE_NAME') and ts.name = dt.tablespace_name ) select e.run_time,e.name,e.alloc_size_gb,e.used_size_gb curr_used_size_gb,b.used _size_gb prev_used_size_gb, case when e.used_size_gb > b.used_size_gb then to_char(e.used_size_gb - b.used_s ize_gb) when e.used_size_gb = b.used_size_gb then '***NO DATA GROWTH' when e.used_size_gb < b.used_size_gb then '******DATA PURGED' end variance from t e, t b where e.run_time = b.run_time + 1 order by 1; --TO MAIL THE REPORT AS AN ATTACHMENT !ls -1tr *csv|tail -1|awk '{print "uuencode " $1,$1 "|mailx -s $ORACLE_SID jp.vi jaykumar@gmail.com"}'|ksh

select name, (select round(sum(bytes)/1024/1024/1024,2) from dba_data_files where tabl espace_name=a.name) df_alloc_gb, round(tablespace_size*8192/1024/1024/1024,2) hs_alloc_gb, (select round(sum(bytes)/1024/1024/1024,2) from dba_segments where tables pace_name=a.name) ds_used_gb, round(tablespace_usedsize*8192/1024/1024/1024,2) hs_used_gb from v$tablespace a, dba_hist_tbspc_space_usage hs where a.name=upper('&name') and a.ts# = hs.tablespace_id and hs.snap_id = (select max(snap_id) from dba_hist_tbspc_space_usage ); *************************************************************** *************************************************************** --TO CALCULATE AVG GROWTH, DEVIDE THE FREESPACE / AVG GROWTH AND FIND THE NUM DAYS THE AVAILABLE FREESPACE CAN BE SUSTAINED set serverout on size 1000000 linesize 200 echo off feedback off timing off spool jp.xls declare

/************************************************************************ CONSIDERING ONLY 22 WORKING DAYS PER MONTH, AVG_VARIANCE IS MULTIPLIED BY A FACT OR(7/5.5) ************************************************************************/ v_avg number; begin dbms_output.put_line('DB_NAME,RUN_DATE,TS_NAME,ALLOCATED_SIZE_GB,USED_SIZE_GB,FR EE_SIZE_GB,VARIANCE,AVG_GROWTH,DAYS,RUN_OUT_DATE'); execute immediate 'alter session set nls_date_format='''||'yyyy-mm-dd'||''' '; for c1 in (select db_name,name from v$tablespace, (select name db_name from v$database) d where (name like '%DATA%' o r name like '%INDEX%' )) ) loop begin for c2 in ( with t as ( select ss.run_time,ts.name,round(su.tablespace_size*dt.block_size/1024/1024/1024 ,2) alloc_size_gb, round(su.tablespace_usedsize*dt.block_size/1024/1024/1024,2) used_size_gb from dba_hist_tbspc_space_usage su, (select trunc(BEGIN_INTERVAL_TIME) run_time,max(snap_id) snap_id from dba_hist_s napshot group by trunc(BEGIN_INTERVAL_TIME) ) ss, v$tablespace ts, dba_tablespaces dt where su.snap_id = ss.snap_id and su.tablespace_id = ts.ts# and ts.name =c1.name and ts.name = dt.tablespace_name ) select e.run_time,e.name,e.alloc_size_gb,e.used_size_gb curr_used_size_gb,b.used _size_gb prev_used_size_gb, (e.alloc_size_gb - e.used_size_gb) free_size_gb, round(((e.alloc_size_gb - e.use d_size_gb)/avg_vrn )*(7/5.5)) num_days,avg_vrn, e.used_size_gb - b.used_size_gb variance from t e, t b, (select --case when avg(variance) < 1 then 1 else round(avg(variance),2) --end avg_vrn from ( select e.run_time,e.name,e.alloc_size_gb,e.used_size_gb curr_used_size_gb,b.used _size_gb prev_used_size_gb, e.used_size_gb - b.used_size_gb variance from t e, t b where e.run_time = b.run_time + 1 and (e.used_size_gb - b.used_size_gb) > 0 ) ) where e.run_time = b.run_time + 1 and (e.used_size_gb - b.used_size_gb) > 0 order by 1) loop begin dbms_output.put_line(c1.db_name||','||c2.run_time||', '||c2.name||', '||c2.alloc _size_gb||', '||c2.curr_used_size_gb||', '|| c2.free_size_gb ||', '||c2.variance||', '|| c2.avg_vrn||', '||c2.num_days||', '| |(c2.run_time +c2.num_days)); exception when others then

null; end; end loop; exception when others then null; end; end loop; end; / Happy Scripting

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy