Subscribe to Posts by Email

Subscriber Count

    701

Disclaimer

All information is offered in good faith and in the hope that it may be of use for educational purpose and for Database community purpose, but is not guaranteed to be correct, up to date or suitable for any particular purpose. db.geeksinsight.com accepts no liability in respect of this information or its use. This site is independent of and does not represent Oracle Corporation in any way. Oracle does not officially sponsor, approve, or endorse this site or its content and if notify any such I am happy to remove. Product and company names mentioned in this website may be the trademarks of their respective owners and published here for informational purpose only. This is my personal blog. The views expressed on these pages are mine and learnt from other blogs and bloggers and to enhance and support the DBA community and this web blog does not represent the thoughts, intentions, plans or strategies of my current employer nor the Oracle and its affiliates or any other companies. And this website does not offer or take profit for providing these content and this is purely non-profit and for educational purpose only. If you see any issues with Content and copy write issues, I am happy to remove if you notify me. Contact Geek DBA Team, via geeksinsights@gmail.com

Pages

Sql Tuning Advisory & SQL Access Advisory Steps

/* To see if the same task name exists */

	SQL> select OWNER,TASK_ID,TASK_NAME,ADVISOR_NAME,CREATED,LAST_MODIFIED,LAST_EXECUTION, 
	EXECUTION_TYPE,STATUS,STATUS_MESSAGE,RECOMMENDATION_COUNT from dba_advisor_tasks 
	where ADVISOR_NAME in ('SQL Access Advisor','SQL Tuning Advisor'); 

/*Creating a Access Advisor task */

	  DECLARE 
	    task_id NUMBER; 
	    task_name VARCHAR2(30); 
	  BEGIN 
	    task_name := 'ACCESSFORTEST01'; 
	  DBMS_ADVISOR.CREATE_TASK(DBMS_ADVISOR.SQLACCESS_ADVISOR, task_id, task_name); 
	  END; 
	  / 

/* Create a Sql Tuning Set */

	exec DBMS_SQLTUNE.CREATE_SQLSET(sqlset_name => 'SQLTUNINGSET_TEST01_01'); 

/* to check details of the sts created */

	SQL>select * from dba_sqlset WHERE name='SQLTUNINGSET_TEST01_01'; 

/* For checking any previous workload */

	SQL> select * from dba_advisor_sqla_wk_map; 

/* Create a STS workload repository from AWR */

	DECLARE 
	  cur sys_refcursor; 
	BEGIN 
	open cur for 
	   select value(p) from table(dbms_sqltune.select_workload_repository( 
	      begin_snap => 12496,  
	      end_snap => 12513,    
	      basic_filter => 'parsing_schema_name not in 
			 (''DBSNMP'',''SYS'',''ORACLE_OCM'')', 
	      ranking_measure1 => 'elapsed_time', 
	      result_limit => 250)) p; 
	    dbms_sqltune.load_sqlset('SQLTUNINGSET_TEST01_01',cur);
	  close cur; 
	END; 
	/ 

We can either load the STS to Access Advisor or SQL Tuning Advisor

Loading the STS to Sql Tuning Advisor

/* Load the STS to SQL Tuning Advisor */

	DECLARE 
	l_sql_tune_task_id  VARCHAR2(100); 
	BEGIN 
	l_sql_tune_task_id := DBMS_SQLTUNE.create_tuning_task ( 
	sqlset_name => 'SQLTUNINGSET_TEST01_01',  
	scope       => DBMS_SQLTUNE.scope_comprehensive, 
	time_limit  => 30000,
	task_name   => 'sqlset_tuning_task_TEST01_1',
	description => 'Tuning task for an SQL tuning set.'); 
	DBMS_OUTPUT.put_line('l_sql_tune_task_id: ' || l_sql_tune_task_id); 
	END; 
	/ 

/* Execute the tuning task */

	
	EXEC DBMS_SQLTUNE.execute_tuning_task(task_name => 'sqlset_tuning_task_TEST01_1'); 

/* To see recommendations from SQL Tuning Advisor */

	SET LONGCHUNKSIZE 1000000; 
	SET LONG 100000; 
	SET PAGESIZE 1000 
	SET LINESIZE 200 
	SELECT DBMS_SQLTUNE.report_tuning_task('sqlset_tuning_task_TEST01_1') as recommendations from dual

Link STS Workload to SQL Access Advisor Task

	exec dbms_advisor.ADD_STS_REF ('ACCESSFORTEST01','SYS','SQLTUNINGSET_TEST01_01'); 

/* Execute Task */

	exec dbms_advisor.execute_task('ACCESSFORTEST01'); 
	END; 
	/