Call now: 252-767-6166  
Oracle Training Oracle Support Development Oracle Apps

Free Oracle Tips

HTML Text

 Home
 E-mail Us
 Oracle Articles


 Oracle Training
 Oracle News

 Oracle Forum
 Class Catalog


 Our Staff
 Our Prices
 Help Wanted!

 Remote DBA
 Oracle Tuning
 Emergency 911
 RAC Support
 Apps Support
 Analysis
 Design
 Implementation
 Oracle Support


 SQL Tuning
 Security

 UNIX
 Oracle UNIX
 Linux
 Oracle Linux
 Monitoring
 Remote help

 Remote plans
 Remote
services
 Oracle C++
 Oracle Java
 Apache
 JDeveloper
 App Server

 Applications
 Oracle Forms
 Oracle Portal
 11i Upgrades
 SQL Server
 Oracle Concepts
 HTML-DB Tips
 Software Help

 Remote Help  
 Development  

 Implementation


 Financials Training
 Oracle 11i
 Oracle Apps 11i
 Oracle Workflow
 Oracle AR 11i Class
 Oracle AP 11i class
 Oracle GL 11i class
 Oracle HR 11i class
 Oracle FA 11i class
 11i Project Mgt
 11i procurement
 11i collections


 Oracle Posters
 Oracle Books

 Oracle Tuning Book
 Oracle RAC Book
 Oracle Security
 Easy Oracle Books
 Oracle Scripts
 SQL Server DBA
 SQL Design Patterns
 Ion
 Excel-DB   


 BC Oracle News


 Rednecks!
 Dress code
 Arabian Stallion

 Burleson Arabians
 Guide Horses
 Don Burleson Blog
 Golf & Travel


 Privacy Policy
 

 

 
 

dbms_sqltune Package tasks

Oracle Tips by Burleson Consulting

Inside the dbms_sqltune Package tasks

SQL tuning work is one of the most time consuming and challenging tasks faced by Oracle DBAs and application developers and the Oracle10g SQL Tuning Advisor is intended to facilitate SQL tuning tasks and to help the DBA find the optimal SQL execution plan. The SQL Tuning Advisor can search the SQL cache, the AWR, or user inputs searching for inefficient SQL statements. The SQL Tuning Advisor is available through the OEM console, or the dbms_sqltune package can be invoked manually.  Figure 8.3 is a representation of the SQL Tuning Advisor tool in the OEM console.

 

Figure 8.3:  Access SQL Tuning Advisor in the OEM Console.

 

The Ion tool, which has been provided free with the purchase of this book, also supports use of the SQL Tuning Advisor and allows the DBA to tune any SQL statement that is stored in the AWR.  Figure 8.4 is a representation of the SQL Tuning Advisor in the Ion tool.

 

Figure 8.4:  Access SQL Tuning Advisor in Ion

 

The dbms_sqltune package provides the DBA with a PL/SQL API for using the SQL Tuning Advisor tool. Running the SQL Tuning Advisor using PL/SQL API includes two steps:

§       Create the SQL tuning task.

§       Execute the SQL tuning task.

There are several options for the creation of an SQL tuning task. For example, the following process will examine the invocation of a single SQL statement. The dbms_sqltune.create_task function can be used to do the following:

 

DECLARE

  my_sqltext CLOB;

  task_name VARCHAR2(30);

BEGIN

  my_sqltext := 'SELECT object_type, count(*) FROM ';

  my_sqltext := my_sqltext || ' all_objects GROUP BY object_type';

  task_name := DBMS_SQLTUNE.CREATE_TUNING_TASK( sql_text => my_sqltext,

                                   bind_list => sql_binds(anydata.ConvertNumber(100)),

                                   user_name => 'DABR',

                                   scope => 'COMPREHENSIVE',

                                   time_limit => 60,

                                   task_name => 'sql_tuning_task1');

 

END;

/

 

SQL tuning tasks can be created with SQL from the cursor cache, the AWR views, or previously collected SQL Tuning Sets. The overloaded dbms_sqltune.create_task functions are provided to allow the DBA to change the inputs.

 

After successfully creating a SQL tuning task, the DBA can launch the SQL Tuning Optimizer  to produce tuning recommendations. Use the dbms_sqltune.execute_tuning_task procedure to execute the specified task:

 

exec dbms_sqltune.execute_tuning_task ( 'sql_tuning_task1');

 

Now, the DBA is ready to review recommendation details produced by the SQL Tuning Advisor.  A query like the one below can be used to retrieve the SQL analysis results:

 

select dbms_sqltune.report_tuning_task(‘sql_tuning_task1’) from dual;

 

The following is the resulting report.

 

DBMS_SQLTUNE.REPORT_TUNING_TASK('SQL_TUNING_TASK1’)

--------------------------------------------------------------------

GENERAL INFORMATION SECTION

--------------------------------------------------------------------

Tuning Task Name   : SQL_TUNING_TASK1

Scope              : COMPREHENSIVE

Time Limit(seconds): 1800

Completion Status  : COMPLETED

Started at         : 09/07/2004 16:24:41

Completed at       : 09/07/2004 16:24:41

 

--------------------------------------------------------------------

SQL ID  : g2wr3u7s1gtf3

SQL Text: 'SELECT object_type, count(*) FROM

           all_objects GROUP BY object_type'

 

--------------------------------------------------------------------

FINDINGS SECTION (1 finding)

--------------------------------------------------------------------

 

1- Statistics Finding

---------------------

  Optimizer statistics for table "SYS"."OBJ$" and its indices are stale.

 

  Recommendation

  --------------

    Consider collecting optimizer statistics for this table.

    execute dbms_stats.gather_table_stats(ownname => 'SYS',

 

The recommendation report contains problem findings and the corresponding recommendations for fixing them.

 

The analysis process could consume significant processing times. Therefore, the dbms_sqltune package provides an API to manage tuning tasks such as:

§       The interrupt_tuning_task procedure is used to stop the executing task. Any results that have already been produced will be preserved.

§       The cancel_tuning_task procedure terminates the task that is executing without preserving its results.

§       The reset_tuning_task procedure is used to stop the running task and reset it to the initial state.

§       The drop_tuning_task  procedure can be used to remove the task from the database.

During tuning analysis, the SQL Tuning Advisor can recommend and automatically create SQL profiles. The SQL profile is a special object that is used by the optimizer. The SQL Profile contains auxiliary statistics specific to a particular SQL statement.

 

The SQL optimizer uses the information in the SQL profile to adjust the execution plan for the SQL statement that has the associated SQL profile. SQL profiles are great for SQL tuning because it is possible to tune SQL statements without any modification of the application source code or the text of SQL queries. The dba_sql_profiles view shows information about all existing SQL profiles.

 

The dbms_sqltune package can be used to manage SQL profiles. The SQL Tuning Advisor  can recommend the use of a specific SQL Profile. This SQL profile can be associated with SQL statements that are being analyzed by accepting it using dbms_sqltune.accept_sql_profile:

 

DECLARE

  sqlprofile VARCHAR2(30);

BEGIN

  sqlprofile := dbms_sqltune.accept_sql_profile (

  task_name => 'sql_tuning_task1',

  name => 'sql_profile1');

END;

 

After the profile is defined, the DBA can alter any stored SQL profile attributes such as status  , name , description , and category  using dbms_sqltune.alter_sql_profile. The category attribute is used to limit user sessions that can use the particular SQL profile. There is an initialization parameter called sqltune_category , which allows the DBA to set up the default SQL profile category for the database.

 

The dbms_sqltune.drop_sql_profile  procedure is used to remove the SQL profile from the database.

 

The dbms_sqltune package also provides a PL/SQL API to work with SQL Tuning Sets (STS). The STS is a database object that contains one or more SQL statements combined with their execution statistics and context such as particular schema, application module name, list of bind variables, etc. The STS also includes a set of basic execution statistics such as CPU and elapsed times, disk reads and buffer gets, number of executions, etc.

 

When creating a STS, the SQL statements can be filtered by different patterns such as application module name or execution statistics, such as high disk reads. Once created, STS can be an input source for the SQL Tuning Advisor.

 

Typically, the following steps are used to work with STS using the dbms_sqltune API:

1.     STS is created using the dbms_sqltune.create_sqlset procedure. For example, the following script can be used to create a STS called SQLSET1:

 

exec dbms_sqltune.create_sqlset ( ‘SQLSET1’);

 

2.     STS is loaded from such sources as the AWR, another STS, or the cursor cache. The following sample PL/SQL block loads STS from the current cursor cache:

 

DECLARE

  cur dbms_sqltune.sqlset_cursor;

BEGIN

OPEN cur FOR

SELECT VALUE(p)

FROM TABLE (dbms_sqltune.select_cursor_cache) p;

dbms_sqltune.load_sqlset(

sqlset_name => 'SQLSET1',

populate_cursor => cur);

END;

/

 

3.     An SQL tuning task that uses STS as input can be created and executed like this:

 

exec dbms_sqltune.create_tuning_task (sqlset_name  => ‘SQLSET1’, task_name => ‘TASK1’);

exec dbms_sqltune.execute_tuning_task (‘TASK1’);

 

4.     The following syntax can be used to drop a SQL tuning set when finished:

 

exec dbms_sqltune.drop_sqlset ( ‘SQLSET1’ );

 

All SQL tuning sets created in the database by querying the dba_sqlset , dba_sqlset_binds , dba_sqlset_definitions , and dba_sqlset_statements  views are reviewed. For example, the dbms_sqltune_show_sts.sql query below shows the particular SQL statements associated with STS:

 

SELECT

  s.sql_text,

  s.cpu_time

FROM

  dba_sqlset_statements s,

  dba_sqlset a

WHERE

  a.name = 'SQLSET1'

AND

   s.sqlset_id =   a.id

AND

   rownum <= 10

ORDER BY

  s.cpu_time DESC     

 

Clearly, Oracle10g has introduced a rich set of powerful tools for the DBA to use to identify and resolve possible performance problems and while these advisors cannot yet replicate the behavior of a senior DBA, they promise to get more intelligent with each new release of Oracle.

 

SEE CODE DEPOT FOR FULL SCRIPTS


This is an excerpt from my latest book "Oracle Tuning: The Definitive Reference". 

You can buy it direct from the publisher for 30%-off and get instant access to the code depot of Oracle tuning scripts:

http://www.rampant-books.com/book_2005_1_awr_proactive_tuning.htm

 


 

 

  
 

 Oracle cruise
 
 
 
Oracle performance tuning software
 
 

Oracle performance tuning book

 

 
 
 
Oracle performance Tuning 10g reference poster
 
 
 
Oracle training in Linux commands
 
Oracle training Excel
 
Oracle training & performance tuning books
 

 

Burleson is the American Team

Note: This Oracle documentation was created as a support and Oracle training reference for use by our DBA performance tuning consulting professionals.  Feel free to ask questions on our Oracle forum.

Verify experience! Anyone considering using the services of an Oracle support expert should independently investigate their credentials and experience, and not rely on advertisements and self-proclaimed expertise. All legitimate Oracle experts publish their Oracle qualifications.

Errata?  Oracle technology is changing and we strive to update our BC Oracle support information.  If you find an error or have a suggestion for improving our content, we would appreciate your feedback.  Just  e-mail:  and include the URL for the page.
 
 


Burleson Consulting

The Oracle of Database Support

Oracle Performance Tuning

 

Remote DBA Services


 

Copyright © 1996 -  2009 by Burleson Enterprises, Inc. All rights reserved.

Oracle © is the registered trademark of Oracle Corporation.