Welcome to Scribd, the world's digital library. Read, publish, and share books and documents. See more
Download
Standard view
Full view
of .
Look up keyword
Like this
1Activity
0 of .
Results for:
No results containing your search query
P. 1
Where Is My Proc?

Where Is My Proc?

Ratings: (0)|Views: 43|Likes:
Published by jp_vijaykumar
Sql scripting
Sql scripting

More info:

Published by: jp_vijaykumar on Jan 30, 2011
Copyright:Attribution Non-commercial

Availability:

Read on Scribd mobile: iPhone, iPad and Android.
download as TXT, PDF, TXT or read online from Scribd
See more
See less

01/30/2011

pdf

text

original

 
WHERE IS MY PROCAuthor JP Vijaykumar Oracle DBADate Jan 14th 2011Prelude:When you are performing a dml operation, first check, how many rowsare going to be manipulated through the sql query.If the number of rows changing through the sql query are few,then you can execute through a sql query and commit the changes.But if you are changing a large number of rows, it is good ideato use a cursor loop to manipulate the data, intermittently committhe changes.When you are running a long running procedure, without intermittentcommits, most of the time you will be worried, what the procedure isdoing and where is it?In pl/sql, any messages displayed using dbms_output.put_line,will not be displayed, until the procedure is complete.In some procedures, at regular intervals, we insert messagesinto a status log tables and commit. We can regularly see thesecommitted messages from status log tables, to know where the procedure is.In some cursor loops, at regular intervals, we perform batch commits.By querying the table and querying the committed data, we can estimatethe amount of work completed.What if the procedure is not doing any dml activity, no messagesare inserted into status log tables & committed nor intermittent batchcommitts issued. Then you had no clue, as to what the procedure isduring its long hours of execution. Whrere is it?Let us explore, the ways and means to check what my procedure is doingand where it is?------------------------------------------------------------------------select sys_context('USERENV','SID') from dual;SYS_CONTEXT('USERENV','SID')-----------------------------------11select distinct sid from v$mystat;SID----------11--I captured the session_id, before running my test jobs.--Executed test 01set serverout on size 1000000 timing ondeclarev_num number;
 
beginfor i in 1..1000000 loopbegin--execute immediate 'update temp_jp set col1 = 'i',col2=''''sita''''';execute immediate 'select 'i' from dual' into v_num;exceptionwhen others thendbms_output.put_line(sqlerrm);end;end loop;dbms_output.put_line('completed');end;/PL/SQL procedure successfully completed.Elapsed: 00:18:25.11--Executed test 02set serverout on size 1000000 timing ondeclarev_num number;beginfor i in 1..1000000 loopbeginexecute immediate 'update temp_jp set col1 = 'i',col2=''''sita'''' ';--execute immediate 'select 'i' from dual' into v_num;exceptionwhen others thendbms_output.put_line(sqlerrm);end;end loop;dbms_output.put_line('completed');end;/PL/SQL procedure successfully completed.Elapsed: 00:22:29.78--Executed test 03Rollback complete.Elapsed: 00:00:20.42--------------------------------------------------------------------------From a second session, I monitored my procedural run in the db.select addr, xidusn, used_ublk,used_urec from v$transaction where addrin (select taddr from v$session where sid=11);no rows selected (test 01)--Since the session is not doing any dml operation, v$transaction is notreturning any rows.
 
--If used_ublk,used_urec are decreasing, the session is rolling back--If used_ublk,used_urec are increasing, the session is performing dml operation.ADDR XIDUSN USED_UBLK USED_UREC---------------- ---------- ---------- ----------000000008EA79520 5 105 6526 (test 02)--As the session is performing dml, v$transaction view is populated.ADDR XIDUSN USED_UBLK USED_UREC---------------- ---------- ---------- ----------000000008EA79520 5 1284 80328 (test 02)--Notice, the used_ublk,used_urec are increasing, as the session isperforming dml operation.ADDR XIDUSN USED_UBLK USED_UREC---------------- ---------- ---------- ----------000000008EA79520 5 4435 277714(test 03)SQL> /ADDR XIDUSN USED_UBLK USED_UREC---------------- ---------- ---------- ----------000000008EA79520 5 3694 231255(test 03)SQL> /ADDR XIDUSN USED_UBLK USED_UREC---------------- ---------- ---------- ----------000000008EA79520 5 2322 145332(test 03)--Notice, the used_ublk,used_urec are decreasing, as the session is rollingback.Column username format a15Select sid,serial#,username, sofar ,totalwork, time_remaining,sql_textFrom v$sql s, v$session_longops slopWhere sid = 11and sql_address = addressAnd sql_hash_value = hash_valueAnd sofar <> totalwork;no rows selected (test 01)--The session_longops view is not populated, as there is no dml activity.no rows selected (test 02)--The session_longops view is not populated, even while perfoming dml activity.no rows selected(test 03)select 'alter system kill session 'chr(39)sid','serial#chr(39)';'from v$session where sid =11;'ALTERSYSTEMKILLSESSION'CHR(39)SID','SERIAL#CHR(39)';'

You're Reading a Free Preview

Download
scribd
/*********** DO NOT ALTER ANYTHING BELOW THIS LINE ! ************/ var s_code=s.t();if(s_code)document.write(s_code)//-->