{"id":197,"date":"2017-08-17T23:20:52","date_gmt":"2017-08-17T23:20:52","guid":{"rendered":"http:\/\/www.mrmarkyoung.com\/oracle\/?p=197"},"modified":"2018-06-05T17:06:16","modified_gmt":"2018-06-05T07:06:16","slug":"how-to-create-an-oracle-sql-tuning-task-manually-with-the-sql_id","status":"publish","type":"post","link":"http:\/\/www.mrmarkyoung.com\/oracle\/2017\/08\/17\/how-to-create-an-oracle-sql-tuning-task-manually-with-the-sql_id\/","title":{"rendered":"How to Create an Oracle SQL TUNING TASK manually with the SQL_ID"},"content":{"rendered":"<p>Step 1: Get the sql_id of the oracle session you would like to tune. There are a number of ways to get this, this is probably the easiest.<\/p>\n<pre class=\"lang:default decode:true \" >select x.sid\r\n,x.serial#\r\n,x.username\r\n,x.sql_id\r\n,x.sql_child_number\r\n,optimizer_mode\r\n,hash_value\r\n,address\r\n,sql_text\r\nfrom v$sqlarea sqlarea\r\n,v$session x\r\nwhere x.sql_hash_value = sqlarea.hash_value\r\nand x.sql_address = sqlarea.address\r\nand x.username is not null;<\/pre>\n<p>Step 2: Create the tuning task by using the SQL identified from. We can also increase the time to avoid &#8220;Error: ORA-13639: The current operation was interrupted because it timed out.&#8221;<\/p>\n<pre class=\"lang:default decode:true \" >SET SERVEROUTPUT ON\r\ndeclare\r\nstmt_task VARCHAR2(40);\r\nbegin\r\nstmt_task := DBMS_SQLTUNE.CREATE_TUNING_TASK(sql_id =&gt; '4ztz048yfq32s', scope =&gt; DBMS_SQLTUNE.scope_comprehensive, time_limit =&gt; 7200);\r\nDBMS_OUTPUT.put_line('task_id: ' || stmt_task );\r\nend;\r\n\/\r\ntask_id: TASK_47302<\/pre>\n<p>Step 3: Run the SQL TUNING TASK<\/p>\n<pre class=\"lang:default decode:true \" >begin\r\nDBMS_SQLTUNE.EXECUTE_TUNING_TASK(task_name =&gt; 'TASK_47302');\r\nend;\r\n\/<\/pre>\n<p>You can monitor the processing of the tuning task with the statement<\/p>\n<pre class=\"lang:default decode:true \" >SELECT TASK_NAME, STATUS FROM DBA_ADVISOR_LOG WHERE TASK_NAME = 'TASK_47302';<\/pre>\n<p>Step 4. When the task has a status=COMPLETED, then run:<\/p>\n<pre class=\"lang:default decode:true \" >SELECT DBMS_SQLTUNE.REPORT_TUNING_TASK('TASK_47302') AS recommendations FROM dual;<\/pre>\n<p>Step 5. Examine the recommendations from Oracle, in case you agree, then accept the best SQL profile.<\/p>\n<pre class=\"lang:default decode:true \" >begin\r\nDBMS_SQLTUNE.ACCEPT_SQL_PROFILE(task_name =&gt; 'TASK_47302', task_owner =&gt; 'SYSTEM', replace =&gt; TRUE);\r\nend;\r\n\/<\/pre>\n<p>Step 6. You can check the database sql profiles with the statement:<\/p>\n<pre class=\"lang:default decode:true \" >select * from dba_sql_profiles;<\/pre>\n<p>In case you want to disable an sql profile use the statement:<\/p>\n<pre class=\"lang:default decode:true \" >begin\r\nDBMS_SQLTUNE.ALTER_SQL_PROFILE('SQL_PROFILE','STATUS','DISABLED');\r\nend;\r\n\/<\/pre>\n","protected":false},"excerpt":{"rendered":"<p>Step 1: Get the sql_id of the oracle session you would like to tune. There are a number of ways to get this, this is probably the easiest. select x.sid ,x.serial# ,x.username ,x.sql_id ,x.sql_child_number ,optimizer_mode ,hash_value ,address ,sql_text from v$sqlarea sqlarea ,v$session x where x.sql_hash_value = sqlarea.hash_value and x.sql_address = sqlarea.address and x.username is not &#8230; <a title=\"How to Create an Oracle SQL TUNING TASK manually with the SQL_ID\" class=\"read-more\" href=\"http:\/\/www.mrmarkyoung.com\/oracle\/2017\/08\/17\/how-to-create-an-oracle-sql-tuning-task-manually-with-the-sql_id\/\" aria-label=\"Read more about How to Create an Oracle SQL TUNING TASK manually with the SQL_ID\">Read more<\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[4],"tags":[54],"class_list":["post-197","post","type-post","status-publish","format-standard","hentry","category-oracle-database","tag-performance"],"_links":{"self":[{"href":"http:\/\/www.mrmarkyoung.com\/oracle\/wp-json\/wp\/v2\/posts\/197","targetHints":{"allow":["GET"]}}],"collection":[{"href":"http:\/\/www.mrmarkyoung.com\/oracle\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/www.mrmarkyoung.com\/oracle\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/www.mrmarkyoung.com\/oracle\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/www.mrmarkyoung.com\/oracle\/wp-json\/wp\/v2\/comments?post=197"}],"version-history":[{"count":3,"href":"http:\/\/www.mrmarkyoung.com\/oracle\/wp-json\/wp\/v2\/posts\/197\/revisions"}],"predecessor-version":[{"id":200,"href":"http:\/\/www.mrmarkyoung.com\/oracle\/wp-json\/wp\/v2\/posts\/197\/revisions\/200"}],"wp:attachment":[{"href":"http:\/\/www.mrmarkyoung.com\/oracle\/wp-json\/wp\/v2\/media?parent=197"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/www.mrmarkyoung.com\/oracle\/wp-json\/wp\/v2\/categories?post=197"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/www.mrmarkyoung.com\/oracle\/wp-json\/wp\/v2\/tags?post=197"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}