Tag Archives: automation

Tablespace Utilization Trend and Forecasting

As a DBA, everyday we have a responsibility to keep sufficient space in tablespace across the fleet. And when the fleet is large, you have thousands of tablespace to monitor. And sometimes it is unpredictable behavior in growth due to change in business requirement, bad code or bad planning by application teams, which result in incidents. Everyone has their own workflow and tools. Some uses Enterprise Manager, some uses their own custom solutions.

To ease the monitoring and forecasting, I use following workflow:

    1. Data Collection – collect the utilization every day from all the databases and put in repository.
    2. Visualization – collected data is then visualized in a lattice graph (one graph per instance with top tablespaces as series in each plot). You can use excel, google charts etc to do this.
    3. Monitor – you can choose to manually look into the plot and take necessary actions
    4. Drill Down and Automatic prediction using linear regression – When I found anything suspicious in monitoring, I further drill down and use oracle linear regression function to predict 100% date. You can get the SQL from my github repository which generates the Plot and Provide you top objects and also the prediction date.  One can also create reports like Top 20 tablespaces, Top 20 fastest growing tablespace etc.

2015-02-23_19-02-53

The math behind the prediction is quite simple. I am using oracle provided analytics function like REGR_INT, REGR_R2 and REGR_INTERCEPT which can be used to perform linear regression on the timeseries data like tablespace utilization.  Also note that you need to convert the timestamp data into Julian formatted date to use regression functions.

The visualization is done by using Google charts. I was inspired by Carlos Sierra’s blog post on creating line charts using google charts API.

SELECT DDATE, instance_name, tablespace_name,
 megs_alloc number_column_1,
 megs_used number_column_2,
 --regr_intercept(ddate - to_date('19700101 00:00:00','YYYYMMDD HH24:MI:SS'), megs_alloc - megs_used) over (partition by tablespace_name) as regr_int,
 (to_date('19700101 00:00:00','YYYYMMDD HH24:MI:SS')+ regr_intercept(ddate - to_date('19700101 00:00:00','YYYYMMDD HH24:MI:SS'), megs_alloc - megs_used) over (partition by tablespace_name)) as predicted_date,
 regr_r2(ddate - to_date('19700101 00:00:00','YYYYMMDD HH24:MI:SS'), megs_alloc - megs_used) over (partition by tablespace_name) as coeff_of_determination  
 FROM MON_TABLESPACE
 WHERE     
instance_name  = substr('&&metric_selected.', 0,instr('&&metric_selected.',':')-1) 
AND tablespace_name  = substr('&&metric_selected.', instr('&&metric_selected.',':')+1)      AND ddate >  (SYSDATE) - nvl(&&report_period., 1) 
order by DDATE asc 

Generating ADDM report Automatically

Database tuning is always ongoing effort and it never stops. Similar doing health checks are like gold mine. You never know what you will get it. From Oracle DB 10g onwards, we have a facility to generate ADDM reports which often is neglected. With growing databases under my hood, I was bit negligent reviewing performance of some least used database or those which were not coming in picture very often. I thought of automating the tuning and reviewing which may help me to efficiently monitor the database performance and keep a track of what is going on in my database.

So here is my workflow.

1. Automate the ADDM report of last day for each database.

2. Send an email report to yourself and team

3. Ask team members to have a quick look every day on these reports

4. Run tuning advisor and segment advisor and review the result

5. Take actions

Hopefully, we will rip this gold mine of data for performance tuning.

Here is the script to generate ADDM report of last day.

/*
 * Purpose: To generate ADDM report manually
 * 
 * Author: Anjul Sahu
 * 
 * History: 
 * 25-SEP-2014	anjul	initial version
 * 
 */
 

SET LONG 1000000
SET LINES 1000 PAGES 0
SET FEEDBACK ON TIMING OFF VERIFY OFF
SPOOL last_day_addm_report.txt

DECLARE
   dbid           NUMBER;
   bid            NUMBER;
   eid            NUMBER;
   db_unique_name VARCHAR2(30);  
   host_name      VARCHAR2(64);
   status         VARCHAR2(11);
   starttime      CHAR (5);
   endtime        CHAR (5);
   output         VARCHAR2 (32000);
   tname varchar2(50);
   tid   number;  
BEGIN
   --starttime := '00:00';
   --endtime := '23:00';
	dbms_output.enable(100000);
   SELECT MIN (snap_id)-1, MAX (snap_id)+1
     INTO bid, eid
     FROM dba_hist_snapshot
    WHERE 
      --TO_CHAR (begin_interval_time, 'hh24:mi') >= starttime
      --AND TO_CHAR (end_interval_time, 'hh24:mi') <= endtime
      --AND 
      TRUNC (begin_interval_time) = TRUNC (SYSDATE-1)
      AND TRUNC (end_interval_time) = TRUNC (SYSDATE-1);
 
   SELECT dbid, db_unique_name
     INTO dbid, db_unique_name
     FROM v$database;
 
   SELECT host_name INTO host_name
     FROM v$instance;
    
    DBMS_ADVISOR.CREATE_TASK('ADDM',tid,tname,'ADDM Report( '
    || bid || ',' || eid || ' )');
    DBMS_ADVISOR.SET_TASK_PARAMETER( tname,'START_SNAPSHOT',bid );
    DBMS_ADVISOR.SET_TASK_PARAMETER( tname,'END_SNAPSHOT',eid );
    DBMS_ADVISOR.EXECUTE_TASK( tname );    
    
    status := 0;
    
    while status  'COMPLETED' loop
    select status into status from dba_advisor_tasks where task_id = tid;
    dbms_lock.sleep(5);    
    end loop;

 
 
   SELECT DBMS_ADVISOR.GET_TASK_REPORT( tname) INTO output FROM DUAL;
   DBMS_OUTPUT.PUT_LINE(output); 

EXCEPTION
   WHEN OTHERS THEN
    dbms_output.put_line('Error Occurred...'||SQLCODE);
    NULL;
END;
/
SPOOL OFF
exit