{"id":1044,"date":"2006-08-04T12:00:00","date_gmt":"2006-08-04T12:00:00","guid":{"rendered":"http:\/\/orcldoug.com\/blog\/?p=1044"},"modified":"2006-08-04T12:00:00","modified_gmt":"2006-08-04T12:00:00","slug":"tracing-session-activity-over-a-remote-database-link","status":"publish","type":"post","link":"http:\/\/orcldoug.com\/blog\/2006\/08\/04\/tracing-session-activity-over-a-remote-database-link\/","title":{"rendered":"Tracing session activity over a remote database link"},"content":{"rendered":"<p>Yesterday someone asked me how to trace a session that selects from a view in a remote database via a link. If they activated the trace on the local instance, they wouldn&#8217;t see the bulk of the work which was happening on the remote instance &#8211; just a bunch of SQL*Net Message from dblink waits.<\/p>\n<p>There are a number of ways to approach this. For example, using Active Session History (ASH)\u00a0on the remote database might give you the information you&#8217;re looking for without tracing, but only if you&#8217;re on 10g. I proposed a solution that&#8217;ll work on version 8.1 and later and tested it on 9.2.0.4<\/p>\n<p>I suggested using a login trigger on the remote database because it would ensure that all of the remote work was captured properly without needing to go into the remote database, quickly spot the session of interest and enable tracing on it. The requirement was further complicated by the fact that this job is probably using parallel query. I was initially sure that I&#8217;d find tons of web references to this, but was surprised to be wrong, so I thought I may as well stick a simple example on the blog. I&#8217;ve stripped out a few lines here and there to make it shorter, but hopefully the gist is clear.<\/p>\n<p>First I&#8217;ll go into the remote database and create the trigger. (Note &#8211; the only reason I forced parallel query on within the trigger was to simulate the questioner&#8217;s requirement more accurately)<\/p>\n<pre><code>SQL&gt; select name from v$database;<br\/><br\/>NAME<br\/>---------<br\/>REMOTE92<br\/><br\/>SQL&gt; connect \/ as sysdba<br\/>Connected.<br\/>SQL&gt; create trigger trace_testuser<br\/>2\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 after logon on TESTUSER.schema<br\/>3\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 begin<br\/>4\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 execute immediate 'alter session set events ''10046 trace name context<br\/>forever, level 8''';<br\/>5\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 execute immediate 'alter session force parallel query';<br\/>6 end;<br\/>7 \/<br\/><br\/>Trigger created.<\/code><\/pre>\n<p>Next I&#8217;ll check that there are no current TESTUSER sessions running on the remote database &#8230; <\/p>\n<pre><code>SQL&gt; select * from v$session where username = 'TESTUSER';<br\/><br\/>no rows selected<\/code><\/pre>\n<p>and (at the shell prompt) check that there are no stray trace files kicking around that would confuse the end results.<\/p>\n<pre><code>[oracle@ISP4400 udump]$ pwd<br\/>\/home\/oracle\/admin\/REMOTE92\/udump<br\/><br\/>[oracle@ISP4400 udump]$ ls -ltra<br\/>total 16<br\/>drwxr-xr-x 8 oracle dba 4096 Aug 3 23:58 ..<br\/>drwxr-xr-x 2 oracle dba 4096 Aug 3 23:58 .<br\/><br\/>[oracle@ISP4400 udump]$ cd ..\/bdump<br\/><br\/>[oracle@ISP4400 bdump]$ ls -ltra<br\/>total 32<br\/>drwxr-xr-x 8 oracle dba 4096 Aug 3 23:58 ..<br\/>drwxr-xr-x 2 oracle dba 4096 Aug 4 00:05 .<br\/>-rw-r--r-- 1 oracle dba 9447 Aug 4 00:22 alert_REMOTE92.log<\/code><\/pre>\n<p>Now that the remote instance is prepared, I&#8217;ll connect to the local instance &#8211; the one the job will run in &#8211; and show the different database name and database link details.<\/p>\n<pre><code>SQL&gt; connect \/ as sysdba<br\/>Connected.<br\/>SQL&gt; select name from v$database;<br\/><br\/>NAME<br\/>---------<br\/>TEST92<br\/><br\/>SQL&gt; select * from dba_db_links<br\/>2 \/<br\/><br\/>OWNER<br\/>------------------------------<br\/>DB_LINK<br\/>--------------------------------------------------------------------------------<br\/>USERNAME<br\/>------------------------------<br\/>HOST<br\/>--------------------------------------------------------------------------------<br\/>CREATED<br\/>---------<br\/>PUBLIC<br\/>REMOTE92_TESTUSER<br\/>TESTUSER<br\/>REMOTE92<br\/>04-AUG-06<\/code><\/pre>\n<p>Now I&#8217;ll connect as TESTUSER and simulate application activity across the database link.<\/p>\n<pre><code>SQL&gt; connect testuser\/testuser<br\/>Connected.<br\/>SQL&gt; select count(*) from test_tab1@remote92_testuser;<br\/><br\/>COUNT(*)<br\/>----------<br\/>1024000<\/code><\/pre>\n<p>Hopefully the remote instance will have generated a few trace files for the activity.<\/p>\n<pre><code>[oracle@ISP4400 bdump]$ ls -ltra<br\/>total 64<br\/>drwxr-xr-x 8 oracle dba 4096 Aug 3 23:58 ..<br\/>-rw-r--r-- 1 oracle dba 9447 Aug 4 00:22 alert_REMOTE92.log<br\/>drwxr-xr-x 2 oracle dba 4096 Aug 4 00:54 .<br\/>-rw-r----- 1 oracle dba 9227 Aug 4 00:54 remote92_p001_4200.trc<br\/>-rw-r----- 1 oracle dba 10568 Aug 4 00:54 remote92_p000_4198.trc<p><\/p><p>[oracle@ISP4400 bdump]$ ls -ltra ..\/udump<br\/>total 36<br\/>drwxr-xr-x 8 oracle dba 4096 Aug 3 23:58 ..<br\/>drwxr-xr-x 2 oracle dba 4096 Aug 4 00:54 .<br\/>-rw-r----- 1 oracle dba 14310 Aug 4 00:55 remote92_ora_4196.trc<\/p><\/code><\/pre>\n<p>Without doubt, the difficult part of this solution is limiting the collection scope. There might be all sorts of TESTUSER sessions on the remote database that I <em>don&#8217;t<\/em> want to trace, but the trigger could be modified to limit the tracing by checking which machine the session is logging in from, to give just one example.<\/p>\n<p>In case people arrive here while searching for how to trace remote activity and bearing in mind this is only one approach,\u00a0all other suggestions are welcome.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Yesterday someone asked me how to trace a session that selects from a view in a remote database via a link. If they activated the trace on the local instance, they wouldn&#8217;t see the bulk of the work which was happening on the remote instance &#8211; just a bunch of SQL*Net Message from dblink waits.&hellip; <a class=\"more-link\" href=\"http:\/\/orcldoug.com\/blog\/2006\/08\/04\/tracing-session-activity-over-a-remote-database-link\/\">Continue reading <span class=\"screen-reader-text\">Tracing session activity over a remote database link<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[],"class_list":["post-1044","post","type-post","status-publish","format-standard","hentry","category-uncategorized","entry"],"jetpack_featured_media_url":"","jetpack-related-posts":[{"id":1050,"url":"http:\/\/orcldoug.com\/blog\/2006\/08\/10\/historical-perspective-part-2\/","url_meta":{"origin":1044,"position":0},"title":"Historical Perspective (Part 2)","date":"August 10, 2006","format":false,"excerpt":"Let's look at items 2 and 3 from the list in my previous blog1) You know you have a performance problem and can re-create it by running a specific part of the application, be it a user interaction or batch job.2) You have an intermittent but recurring performance problem which\u2026","rel":"","context":"Similar post","img":{"alt_text":"","src":"","width":0,"height":0},"classes":[]},{"id":893,"url":"http:\/\/orcldoug.com\/blog\/2005\/12\/19\/another-10046-success\/","url_meta":{"origin":1044,"position":1},"title":"Another 10046 Success","date":"December 19, 2005","format":false,"excerpt":"We're implementing a new packaged application at work. It includes a history import job that takes data in a flat-file and loads it into database tables. It performs some degree of data transformation but, in essence it inserts about 500,000 rows into one table and thousands in to a few\u2026","rel":"","context":"With 7 comments","img":{"alt_text":"","src":"","width":0,"height":0},"classes":[]},{"id":1159,"url":"http:\/\/orcldoug.com\/blog\/2006\/12\/11\/a-more-complex-statspack-example-summary\/","url_meta":{"origin":1044,"position":2},"title":"A More Complex Statspack Example &#8211; Summary","date":"December 11, 2006","format":false,"excerpt":"Looking back at the three blogs (and hopefully the comments, where others have made some very useful contributions), it's all quite unsatisfactory, isn't it? We haven't solved the problem. All we've proved is that the tests aren't equivalent, although I think there's value in that negative result because I was\u2026","rel":"","context":"With 3 comments","img":{"alt_text":"","src":"","width":0,"height":0},"classes":[]},{"id":1697,"url":"http:\/\/orcldoug.com\/blog\/2013\/03\/11\/not-all-deadlocks-are-created-the-same\/","url_meta":{"origin":1044,"position":3},"title":"Not all Deadlocks are created the same","date":"March 11, 2013","format":false,"excerpt":"I've blogged about deadlocks in Oracle at least once before. I said then that although the following message in deadlock trace files is usually true, it isn't always. The following deadlock is not an Oracle error. Deadlocks of\u00a0 this type can be expected if certain SQL statements are\u00a0\u00a0\u00a0\u00a0\u00a0 issued. The\u2026","rel":"","context":"Similar post","img":{"alt_text":"","src":"","width":0,"height":0},"classes":[]},{"id":1117,"url":"http:\/\/orcldoug.com\/blog\/2006\/10\/31\/recovery-design-part-3-what-is-it-with-rac\/","url_meta":{"origin":1044,"position":4},"title":"Recovery Design part 3 &#8211; What is it with RAC?","date":"October 31, 2006","format":false,"excerpt":"For the next few parts of this mini-series, I'm going to start looking at the initial high level design for the system and how well it meets the requirements. First of all I'm going to talk about the most critical database from the business perspective. I'll call it the User\u2026","rel":"","context":"With 16 comments","img":{"alt_text":"","src":"","width":0,"height":0},"classes":[]},{"id":1191,"url":"http:\/\/orcldoug.com\/blog\/2007\/01\/27\/dba-documentation-catalogue\/","url_meta":{"origin":1044,"position":5},"title":"DBA Documentation &#8211; Catalogue","date":"January 27, 2007","format":false,"excerpt":"Prompted by Linda's comment on a previous blog, I thought it might be worth writing a couple of postings on DBA documentation.The first thing you need is a Database Catalogue of some kind.Benefits1) Even an experienced DBA arriving on site won't know what servers exist, how to login to them,\u2026","rel":"","context":"With 11 comments","img":{"alt_text":"","src":"","width":0,"height":0},"classes":[]}],"_links":{"self":[{"href":"http:\/\/orcldoug.com\/blog\/wp-json\/wp\/v2\/posts\/1044","targetHints":{"allow":["GET"]}}],"collection":[{"href":"http:\/\/orcldoug.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/orcldoug.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/orcldoug.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/orcldoug.com\/blog\/wp-json\/wp\/v2\/comments?post=1044"}],"version-history":[{"count":0,"href":"http:\/\/orcldoug.com\/blog\/wp-json\/wp\/v2\/posts\/1044\/revisions"}],"wp:attachment":[{"href":"http:\/\/orcldoug.com\/blog\/wp-json\/wp\/v2\/media?parent=1044"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/orcldoug.com\/blog\/wp-json\/wp\/v2\/categories?post=1044"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/orcldoug.com\/blog\/wp-json\/wp\/v2\/tags?post=1044"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}