{"id":7071,"date":"2016-02-05T16:36:45","date_gmt":"2016-02-05T15:36:45","guid":{"rendered":"https:\/\/www.dbi-services.com\/blog\/enable-10046-tracing-for-a-specific-sql\/"},"modified":"2016-02-05T16:36:45","modified_gmt":"2016-02-05T15:36:45","slug":"enable-10046-tracing-for-a-specific-sql","status":"publish","type":"post","link":"https:\/\/www.dbi-services.com\/blog\/enable-10046-tracing-for-a-specific-sql\/","title":{"rendered":"Enable 10046 Tracing for a specific SQL"},"content":{"rendered":"<p>Available methods to enable 10046 trace are described in My Oracle Support Note 376442.1. You can enable 10046-tracing<\/p>\n<p>&#8211; on session level (alter session)<br \/>\n&#8211; for other sessions (e.g. with oradebug, the package DBMS_MONITOR or DBMS_SYSTEM)<\/p>\n<p>What is not covered with the methods above is the possibility to trace a specific SQL-statement, which runs &#8220;somewhen&#8221; in the future on the database. E.g. a SQL, which runs during a next batch job. With the introduction of UTS (Unified Tracing Service) in 11.2., you can actually do exactly that:<\/p>\n<p>I.e. suppose I need a 10046-trace, level 12 of the SQL with SQL_ID cjrha4bzuupzf, which runs somewhen in the next 24 hours. So what I have to do is to just set the event &#8220;sql_trace&#8221; for the SQL_ID:<\/p>\n<p><code><br \/>\nSQL&gt; alter system set events 'sql_trace&#091;sql: cjrha4bzuupzf&#093;  level=12';<br \/>\n<\/code><\/p>\n<p>REMARK: With the introduction of the parameter &#8220;_evt_system_event_propagation&#8221; in 11g (default is TRUE) the event-settings of &#8220;alter system set events&#8221;-commands are also propagated to existing sessions.<\/p>\n<p>Let&#8217;s see if only the statement in question is being traced. From another session I&#8217;m doing the following:<br \/>\nREMARK: I actually want to trace the statement with the GATHER_PLAN_STATISTICS-hint.<\/p>\n<p><code><br \/>\nSQL&gt; select \/* BEFORE TRACE *\/ count(*) from t1 where object_type='INDEX';<br \/>\n&nbsp;<br \/>\n  COUNT(*)<br \/>\n----------<br \/>\n      1432<br \/>\n&nbsp;<br \/>\nSQL&gt; select \/*+ GATHER_PLAN_STATISTICS *\/ count(*) from t1 where object_type='INDEX';<br \/>\n&nbsp;<br \/>\n  COUNT(*)<br \/>\n----------<br \/>\n      1432<br \/>\n&nbsp;<br \/>\nSQL&gt; select \/*+ AFTER TRACE *\/ count(*) from t1 where object_type='INDEX';<br \/>\n&nbsp;<br \/>\n  COUNT(*)<br \/>\n----------<br \/>\n      1432<br \/>\n&nbsp;<br \/>\nSQL&gt; select value from v$diag_info where name = 'Default Trace File';<br \/>\n&nbsp;<br \/>\nVALUE<br \/>\n--------------------------------------------------------------------<br \/>\nD:APPCBLdiagrdbmsgen11204gen11204tracegen11204_ora_11552.trc<br \/>\n<\/code><\/p>\n<p>Below is the content of the produced trace file:<\/p>\n<p><code><br \/>\n=====================<br \/>\nPARSING IN CURSOR #305977200 len=79 dep=0 uid=42 oct=3 lid=42 tim=628480230944 hv=4289550318 ad='7ff95ed9ed80' sqlid='cjrha4bzuupzf'<br \/>\nselect \/*+ GATHER_PLAN_STATISTICS *\/ count(*) from t1 where object_type='INDEX'<br \/>\nEND OF STMT<br \/>\nEXEC #305977200:c=0,e=22,p=0,cr=0,cu=0,mis=0,r=0,dep=0,og=1,plh=3724264953,tim=628480230943<br \/>\nWAIT #305977200: nam='SQL*Net message to client' ela= 1 driver id=1111838976 #bytes=1 p3=0 obj#=15671 tim=628480231942<br \/>\nFETCH #305977200:c=0,e=652,p=0,cr=189,cu=0,mis=0,r=1,dep=0,og=1,plh=3724264953,tim=628480232614<br \/>\nSTAT #305977200 id=1 cnt=1 pid=0 pos=1 obj=0 op='SORT AGGREGATE (cr=189 pr=0 pw=0 time=652 us)'<br \/>\nSTAT #305977200 id=2 cnt=1432 pid=1 pos=1 obj=15671 op='TABLE ACCESS FULL T1 (cr=189 pr=0 pw=0 time=622 us cost=56 size=10024 card=1432)'<br \/>\nFETCH #305977200:c=0,e=1,p=0,cr=0,cu=0,mis=0,r=0,dep=0,og=0,plh=3724264953,tim=628480232838<br \/>\nWAIT #305977200: nam='SQL*Net message to client' ela= 1 driver id=1111838976 #bytes=1 p3=0 obj#=15671 tim=628480232858<br \/>\n*** 2016-02-05 15:11:21.578<br \/>\nWAIT #305977200: nam='SQL*Net message from client' ela= 1336677 driver id=1111838976 #bytes=1 p3=0 obj#=15671 tim=628481569546<br \/>\nCLOSE #305977200:c=0,e=8,dep=0,type=0,tim=628481569645<br \/>\n<\/code><\/p>\n<p>So, as expected, only the SQL with SQL_ID cjrha4bzuupzf has been traced.<\/p>\n<p>To switch off the setting for SQL_ID cjrha4bzuupzf do the following:<\/p>\n<p><code><br \/>\nSQL&gt; alter system set events 'sql_trace&#091;sql: cjrha4bzuupzf&#093;  off';<br \/>\n<\/code><\/p>\n<p>The event settings done with &#8220;alter system set events &#8230;&#8221; are not persistent settings. I.e. after a next restart of the instance the event is no longer active. To set the event persistently you would have to set it in the spfile as well:<\/p>\n<p><code><br \/>\nSQL&gt; alter system set event='sql_trace&#091;sql: cjrha4bzuupzf&#093;  level=12' scope=spfile;<br \/>\n<\/code><\/p>\n<p>If you want to see if an event is currently active on the running instance do the following:<\/p>\n<p><code><br \/>\nSQL&gt; oradebug setmypid<br \/>\nStatement processed.<br \/>\nSQL&gt; oradebug eventdump session<br \/>\nsql_trace&#091;sql: cjrha4bzuupzf&#093;  level=12<br \/>\n<\/code><\/p>\n<p>If you have several events set in your spfile then it&#8217;s difficult to remove a single one of them, because the events are stored concatenated with a &#8220;:&#8221; as a single event. You can just overwrite the current setting or remove them all:<\/p>\n<p><code><br \/>\nSQL&gt; alter system reset event scope=spfile;<br \/>\n<\/code><\/p>\n<p>REMARK: Do not set events (except event 10046) without the instruction from Oracle Support to do so. I also do recommend to NOT set event 10046 in the spfile.<\/p>\n<p>Update on the 18th of December 2017: The tracing of a specific SQL is broken in 12.2. Thanks to Nenad Noveljic who discovered that (see the Comment section below). The issue seems caused by the bugs 25989066 and 25994378 which are fixed in 18.1. More details on the issue in 12.2. can be found in <a title=\"Nenad's Blog\" href=\"http:\/\/nenadnoveljic.com\/blog\/event-propagation-in-oracle-12-2\/\">Nenad&#8217;s Blog<\/a>.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Available methods to enable 10046 trace are described in My Oracle Support Note 376442.1. You can enable 10046-tracing &#8211; on session level (alter session) &#8211; for other sessions (e.g. with oradebug, the package DBMS_MONITOR or DBMS_SYSTEM) What is not covered with the methods above is the possibility to trace a specific SQL-statement, which runs &#8220;somewhen&#8221; [&hellip;]<\/p>\n","protected":false},"author":35,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[229,368,59],"tags":[96,17,209,67],"type_dbi":[],"class_list":["post-7071","post","type-post","status-publish","format-standard","hentry","category-database-administration-monitoring","category-development-performance","category-oracle","tag-oracle","tag-oracle-11g","tag-oracle-12c","tag-performance"],"acf":[],"yoast_head":"<!-- This site is optimized with the Yoast SEO Premium plugin v27.2 (Yoast SEO v27.2) - https:\/\/yoast.com\/product\/yoast-seo-premium-wordpress\/ -->\n<title>Enable 10046 Tracing for a specific SQL - dbi Blog<\/title>\n<meta name=\"description\" content=\"Blog about setting sql_trace event 10046 for a specific SQL_ID in Oracle.\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/www.dbi-services.com\/blog\/enable-10046-tracing-for-a-specific-sql\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Enable 10046 Tracing for a specific SQL\" \/>\n<meta property=\"og:description\" content=\"Blog about setting sql_trace event 10046 for a specific SQL_ID in Oracle.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.dbi-services.com\/blog\/enable-10046-tracing-for-a-specific-sql\/\" \/>\n<meta property=\"og:site_name\" content=\"dbi Blog\" \/>\n<meta property=\"article:published_time\" content=\"2016-02-05T15:36:45+00:00\" \/>\n<meta name=\"author\" content=\"Clemens Bleile\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:creator\" content=\"@ifgtxD2SrQ8r!YuXj\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Clemens Bleile\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"3 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\/\/www.dbi-services.com\/blog\/enable-10046-tracing-for-a-specific-sql\/#article\",\"isPartOf\":{\"@id\":\"https:\/\/www.dbi-services.com\/blog\/enable-10046-tracing-for-a-specific-sql\/\"},\"author\":{\"name\":\"Clemens Bleile\",\"@id\":\"https:\/\/www.dbi-services.com\/blog\/#\/schema\/person\/0ac04011f60f2e93c115358d0789c2da\"},\"headline\":\"Enable 10046 Tracing for a specific SQL\",\"datePublished\":\"2016-02-05T15:36:45+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\/\/www.dbi-services.com\/blog\/enable-10046-tracing-for-a-specific-sql\/\"},\"wordCount\":418,\"commentCount\":1,\"keywords\":[\"Oracle\",\"Oracle 11g\",\"Oracle 12c\",\"Performance\"],\"articleSection\":[\"Database Administration &amp; Monitoring\",\"Development &amp; Performance\",\"Oracle\"],\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\/\/www.dbi-services.com\/blog\/enable-10046-tracing-for-a-specific-sql\/#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\/\/www.dbi-services.com\/blog\/enable-10046-tracing-for-a-specific-sql\/\",\"url\":\"https:\/\/www.dbi-services.com\/blog\/enable-10046-tracing-for-a-specific-sql\/\",\"name\":\"Enable 10046 Tracing for a specific SQL - dbi Blog\",\"isPartOf\":{\"@id\":\"https:\/\/www.dbi-services.com\/blog\/#website\"},\"datePublished\":\"2016-02-05T15:36:45+00:00\",\"author\":{\"@id\":\"https:\/\/www.dbi-services.com\/blog\/#\/schema\/person\/0ac04011f60f2e93c115358d0789c2da\"},\"description\":\"Blog about setting sql_trace event 10046 for a specific SQL_ID in Oracle.\",\"breadcrumb\":{\"@id\":\"https:\/\/www.dbi-services.com\/blog\/enable-10046-tracing-for-a-specific-sql\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/www.dbi-services.com\/blog\/enable-10046-tracing-for-a-specific-sql\/\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/www.dbi-services.com\/blog\/enable-10046-tracing-for-a-specific-sql\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Accueil\",\"item\":\"https:\/\/www.dbi-services.com\/blog\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Enable 10046 Tracing for a specific SQL\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/www.dbi-services.com\/blog\/#website\",\"url\":\"https:\/\/www.dbi-services.com\/blog\/\",\"name\":\"dbi Blog\",\"description\":\"\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/www.dbi-services.com\/blog\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":\"Person\",\"@id\":\"https:\/\/www.dbi-services.com\/blog\/#\/schema\/person\/0ac04011f60f2e93c115358d0789c2da\",\"name\":\"Clemens Bleile\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/secure.gravatar.com\/avatar\/1f596609fc67cb28ed714e7bccc81ed4cd73b8582a8148a490c77daeb2fde21a?s=96&d=mm&r=g\",\"url\":\"https:\/\/secure.gravatar.com\/avatar\/1f596609fc67cb28ed714e7bccc81ed4cd73b8582a8148a490c77daeb2fde21a?s=96&d=mm&r=g\",\"contentUrl\":\"https:\/\/secure.gravatar.com\/avatar\/1f596609fc67cb28ed714e7bccc81ed4cd73b8582a8148a490c77daeb2fde21a?s=96&d=mm&r=g\",\"caption\":\"Clemens Bleile\"},\"description\":\"Clemens Bleile has more than 30 years of IT experience, thirteen in Oracle Support and fifteen in Oracle Consulting. He is specialized in Oracle Database Performance Tuning (SQL Tuning, DB Tuning) and developing an Oracle DB IT architecture (highly available, low-maintenance, cost efficient storage of data). He is an expert in problem analysis and resolution. Prior to joining dbi services, Clemens Bleile was Manager of the EMEA Database Performance team at the Oracle Global Customer Support Services. Clemens Bleile is Oracle Certified Professional 11g, 12c and Oracle Certified Expert for Performance Management and Tuning and holds a Master Degree, Business Information Systems from the Fachhochschule Furtwangen, Germany.\",\"sameAs\":[\"https:\/\/www.dbi-services.com\",\"https:\/\/x.com\/ifgtxD2SrQ8r!YuXj\"],\"url\":\"https:\/\/www.dbi-services.com\/blog\/author\/clemens-bleile\/\"}]}<\/script>\n<!-- \/ Yoast SEO Premium plugin. -->","yoast_head_json":{"title":"Enable 10046 Tracing for a specific SQL - dbi Blog","description":"Blog about setting sql_trace event 10046 for a specific SQL_ID in Oracle.","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/www.dbi-services.com\/blog\/enable-10046-tracing-for-a-specific-sql\/","og_locale":"en_US","og_type":"article","og_title":"Enable 10046 Tracing for a specific SQL","og_description":"Blog about setting sql_trace event 10046 for a specific SQL_ID in Oracle.","og_url":"https:\/\/www.dbi-services.com\/blog\/enable-10046-tracing-for-a-specific-sql\/","og_site_name":"dbi Blog","article_published_time":"2016-02-05T15:36:45+00:00","author":"Clemens Bleile","twitter_card":"summary_large_image","twitter_creator":"@ifgtxD2SrQ8r!YuXj","twitter_misc":{"Written by":"Clemens Bleile","Est. reading time":"3 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/www.dbi-services.com\/blog\/enable-10046-tracing-for-a-specific-sql\/#article","isPartOf":{"@id":"https:\/\/www.dbi-services.com\/blog\/enable-10046-tracing-for-a-specific-sql\/"},"author":{"name":"Clemens Bleile","@id":"https:\/\/www.dbi-services.com\/blog\/#\/schema\/person\/0ac04011f60f2e93c115358d0789c2da"},"headline":"Enable 10046 Tracing for a specific SQL","datePublished":"2016-02-05T15:36:45+00:00","mainEntityOfPage":{"@id":"https:\/\/www.dbi-services.com\/blog\/enable-10046-tracing-for-a-specific-sql\/"},"wordCount":418,"commentCount":1,"keywords":["Oracle","Oracle 11g","Oracle 12c","Performance"],"articleSection":["Database Administration &amp; Monitoring","Development &amp; Performance","Oracle"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/www.dbi-services.com\/blog\/enable-10046-tracing-for-a-specific-sql\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/www.dbi-services.com\/blog\/enable-10046-tracing-for-a-specific-sql\/","url":"https:\/\/www.dbi-services.com\/blog\/enable-10046-tracing-for-a-specific-sql\/","name":"Enable 10046 Tracing for a specific SQL - dbi Blog","isPartOf":{"@id":"https:\/\/www.dbi-services.com\/blog\/#website"},"datePublished":"2016-02-05T15:36:45+00:00","author":{"@id":"https:\/\/www.dbi-services.com\/blog\/#\/schema\/person\/0ac04011f60f2e93c115358d0789c2da"},"description":"Blog about setting sql_trace event 10046 for a specific SQL_ID in Oracle.","breadcrumb":{"@id":"https:\/\/www.dbi-services.com\/blog\/enable-10046-tracing-for-a-specific-sql\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.dbi-services.com\/blog\/enable-10046-tracing-for-a-specific-sql\/"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/www.dbi-services.com\/blog\/enable-10046-tracing-for-a-specific-sql\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Accueil","item":"https:\/\/www.dbi-services.com\/blog\/"},{"@type":"ListItem","position":2,"name":"Enable 10046 Tracing for a specific SQL"}]},{"@type":"WebSite","@id":"https:\/\/www.dbi-services.com\/blog\/#website","url":"https:\/\/www.dbi-services.com\/blog\/","name":"dbi Blog","description":"","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/www.dbi-services.com\/blog\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Person","@id":"https:\/\/www.dbi-services.com\/blog\/#\/schema\/person\/0ac04011f60f2e93c115358d0789c2da","name":"Clemens Bleile","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/secure.gravatar.com\/avatar\/1f596609fc67cb28ed714e7bccc81ed4cd73b8582a8148a490c77daeb2fde21a?s=96&d=mm&r=g","url":"https:\/\/secure.gravatar.com\/avatar\/1f596609fc67cb28ed714e7bccc81ed4cd73b8582a8148a490c77daeb2fde21a?s=96&d=mm&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/1f596609fc67cb28ed714e7bccc81ed4cd73b8582a8148a490c77daeb2fde21a?s=96&d=mm&r=g","caption":"Clemens Bleile"},"description":"Clemens Bleile has more than 30 years of IT experience, thirteen in Oracle Support and fifteen in Oracle Consulting. He is specialized in Oracle Database Performance Tuning (SQL Tuning, DB Tuning) and developing an Oracle DB IT architecture (highly available, low-maintenance, cost efficient storage of data). He is an expert in problem analysis and resolution. Prior to joining dbi services, Clemens Bleile was Manager of the EMEA Database Performance team at the Oracle Global Customer Support Services. Clemens Bleile is Oracle Certified Professional 11g, 12c and Oracle Certified Expert for Performance Management and Tuning and holds a Master Degree, Business Information Systems from the Fachhochschule Furtwangen, Germany.","sameAs":["https:\/\/www.dbi-services.com","https:\/\/x.com\/ifgtxD2SrQ8r!YuXj"],"url":"https:\/\/www.dbi-services.com\/blog\/author\/clemens-bleile\/"}]}},"_links":{"self":[{"href":"https:\/\/www.dbi-services.com\/blog\/wp-json\/wp\/v2\/posts\/7071","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.dbi-services.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.dbi-services.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.dbi-services.com\/blog\/wp-json\/wp\/v2\/users\/35"}],"replies":[{"embeddable":true,"href":"https:\/\/www.dbi-services.com\/blog\/wp-json\/wp\/v2\/comments?post=7071"}],"version-history":[{"count":0,"href":"https:\/\/www.dbi-services.com\/blog\/wp-json\/wp\/v2\/posts\/7071\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.dbi-services.com\/blog\/wp-json\/wp\/v2\/media?parent=7071"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.dbi-services.com\/blog\/wp-json\/wp\/v2\/categories?post=7071"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.dbi-services.com\/blog\/wp-json\/wp\/v2\/tags?post=7071"},{"taxonomy":"type","embeddable":true,"href":"https:\/\/www.dbi-services.com\/blog\/wp-json\/wp\/v2\/type_dbi?post=7071"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}