HOME > > How to fix Long running SQL Issue using Tuning Advisor

How to fix Long running SQL Issue using Tuning Advisor

Anup - Friday, May 10, 2024

 

Step 1. Identify the long running SQL ID for particular SQL Statement 

select 
sqa.sql_id, ss.program "SOFTWARE",
       last_call_et "TIME",
       ss.username "USER",
      SS.ACTION "JOB",
       substr(sqa.sql_text, 1, 50) "SQL"
----,SQA.SQL_FULLTEXT
,'alter system disconnect session ''' || ss.sid || ',' || ss.serial# || ',@' || ss.inst_id || ''' immediate;'
  fROM gv$process pr, gv$session ss, gv$sqlarea sqa
 WHERE pr.addr = ss.paddr
   AND ss.username is not null
   AND ss.sql_address = sqa.address(+)
   AND ss.sql_hash_value = sqa.hash_value(+)
AND ss.status = 'ACTIVE'
ORDER BY last_call_et desc;

Note Down SQLID

Step 2: creating the tuning task

set serveroutput on
declare
  l_sql_tune_task_id  varchar2(100);
begin
  l_sql_tune_task_id := dbms_sqltune.create_tuning_task (
                          sql_id      => 'ENTER_SQL_ID',
                          scope       => dbms_sqltune.scope_comprehensive,
                          time_limit  => 10200,
                          task_name   => 'Enter_Task_Name',
                          description => 'tuning task for statement your_sql_id.');
  dbms_output.put_line('l_sql_tune_task_id: ' || l_sql_tune_task_id);
end;
/

Step 3: Executing the tuning task

exec dbms_sqltune.execute_tuning_task(task_name => 'ENTER_ABOVE_TASk_NAME');

Step 4: Displaying the recommendations 

set long 100000;
set longchunksize 1000
set pagesize 10000
set linesize 100
select dbms_sqltune.report_tuning_task('ENTER_ABOVE_TASk_NAME') as recommendations from dual;

Step 5: review the recommendation 

Contact me

Get in Touch

Need to get touch with me? Please fill out the form with your enquiry.

Name
Anup Srivastav
Address
Lucknow - Utter Pradesh
Email
myindiandba@gmail.com
Message me