SQL TUNING ADVISOR

Breadcrumb Abstract Shape
Breadcrumb Abstract Shape
Breadcrumb Abstract Shape
Breadcrumb Abstract Shape
Breadcrumb Abstract Shape
Breadcrumb Abstract Shape
  • User AvatarKiran Dalvi
  • 12 Dec, 2021
  • 0 Comments
  • 1 Min Read

SQL TUNING ADVISOR

SQL Tuning Advisor - Performance Tuning

SQL Tuning Advisor

How to run SQL Tuning Advisor Manually

SQL Tuning Advisor is SQL diagnostic software in the Oracle Database Tuning Pack. SQL Tuning Advisor is a mechanism for resolving problems related to suboptimally performing SQL statements. Use SQL Tuning Advisor to obtain recommendations for improving performance of high-load SQL statements, and prevent regressions by only executing optimal plans.

Find SQL Id of the Statement You Just Ran
Quickly retrieve the SQL ID of your last executed statement.
While connected to the database, you might want to know the sql id of the query you just ran (in your own session, not some other session).

Let’s run a sample query

set serveroutput off
Select * from hr.employees;

Now you might want to know the SQL ID of the above command. You must query PREV_SQL_ID column from V$SESSION

select prev_sql_id from v$session where sid=sys_context('userenv','sid');

You can check if the sql id returned above is correct by checking the SQL TEXT associated with the sql id

select sql_id, sql_text from v$sqltext 
where sql_id in ('fxdbrc4jhqn5r');

STEP 2: Run the SQL Advisor Manually


DECLARE
    l_sql_tune_task_id VARCHAR2(100);
BEGIN
    l_sql_tune_task_id := DBMS_SQLTUNE.create_tuning_task (
        sql_id => '7uk907hrgrj6j',
        scope => DBMS_SQLTUNE.scope_comprehensive,
        time_limit => 500,
        task_name => '7uk907hrgrj6j_tuning_task11',
        description => 'Tuning task1 for statement 7uk907hrgrj6j'
    );
    DBMS_OUTPUT.put_line('l_sql_tune_task_id: ' || l_sql_tune_task_id);
END;
/

-- Execute the SQL Tuning Task
EXEC DBMS_SQLTUNE.execute_tuning_task(task_name => '7uk907hrgrj6j_tuning_task11');

-- Retrieve and Display the Tuning Report
SET LONG 65536
SET LONGCHUNKSIZE 65536
SET LINESIZE 100
SELECT DBMS_SQLTUNE.report_tuning_task('7uk907hrgrj6j_tuning_task11') FROM dual;


******************************THE END***********************************************