How Oracle monitors the operation of a plsql process (ii) Professional Solutions

Source: Internet
Author: User
Tags requires sleep

Yesterday a friend asked me how to monitor the operation of a pl/sql, here is a brief introduction to several methods.

Introduce a professional Dbms_application_info package.

The previous article introduced a solution through inserts and autonomous transactions, which is simple, but requires auxiliary tables and procedures, and this approach is somewhat unprofessional.

So here's a relatively professional solution, Oracle delivers the Dbms_application_info package:

Sql> SELECT SID, ACTION

2 from V$session

3 WHERE SID in

4 (SELECT SID

5 from V$mystat

6 WHERE rownum = 1);

SID ACTION

---------- --------------------------------

13

Sql> BEGIN

2 Dbms_application_info. Set_action (' Step A ');

3 Dbms_lock. Sleep (10);

4 Dbms_application_info. Set_action (' Step B ');

5 Dbms_lock. Sleep (10);

6 Dbms_application_info. Set_action (' Step C ');

7 End;

8/

The PL/SQL process has completed successfully.

By simply invoking the Set_action procedure, other sessions can be performed by monitoring the V$session view, and from the current pl/sql to which step:

sql> SELECT SID, ACTION from v$session WHERE SID = 13;

SID ACTION

---------- --------------------------------

Step A

sql> SELECT SID, ACTION from v$session WHERE SID = 13;

SID ACTION

---------- --------------------------------

Step A

sql> SELECT SID, ACTION from v$session WHERE SID = 13;

SID ACTION

---------- --------------------------------

Step B

sql> SELECT SID, ACTION from v$session WHERE SID = 13;

SID ACTION

---------- --------------------------------

Step B

sql> SELECT SID, ACTION from v$session WHERE SID = 13;

SID ACTION

---------- --------------------------------

Step C

sql> SELECT SID, ACTION from v$session WHERE SID = 13;

SID ACTION

---------- --------------------------------

Step C

In another session you can see the changes in the pl/sql from step A to step c in the conversation just now. Note that if the session no longer modifies the action, the session's action remains at the end of the conversation.

More Wonderful content: http://www.bianceng.cn/database/Oracle/

The simplicity of this method does not have to be complex to insert, and the Dbms_application_info package is accessible to all users. It should be noted, however, that not all users have access to the V$session view, which requires additional authorization.

The above method does not seem to be very professional, using this package also has a more professional solution:

Sql> SELECT SID, serial#

2 from V$session

3 WHERE SID in

4 (SELECT SID

5 from V$mystat

6 WHERE rownum = 1);

SID serial#

---------- ----------

13 6610

Sql> DECLARE

2 v_id Binary_integer: = Dbms_application_info. Set_session_longops_nohint;

3 V_slno Binary_integer;

4 v_totalwork Number: = 5;

5 BEGIN

6 for I in 1..v_totalwork LOOP

7 Dbms_application_info. Set_session_longops (

8 v_id,

9 V_slno,

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.