Oracle View Object Hold lock condition

Source: Internet
Author: User

Colleagues in the test library on a table plus fields, prompting ORA-00054, resource busy. The lock on the Table object should not be released.

For a description of the Oracle lock, refer to:

Oracle lock mechanism

http://blog.csdn.net/tianlesoftware/article/details/4696896

Use the following SQL to look at the locking of related objects in the system:

[SQL]View PlainCopy
  1. <pre name="code" class="SQL" >/* formatted on 2012/2/13 14:24:32 (QP5 v5.185.11230.41888) */ /c5>
  2. SELECT S.sid session_id,
  3. S.username,
  4. DECODE (Lmode,
  5. 0, ' None ',
  6. 1, ' Null ',
  7. 2, ' Row-s (SS) ',
  8. 3, ' Row-x (SX) ',
  9. 4, ' Share ',
  10. 5, ' S/row-x (SSX) ',
  11. 6, ' Exclusive ',
  12. To_char (Lmode))
  13. Mode_held,
  14. DECODE (REQUEST,
  15. 0, ' None ',
  16. 1, ' Null ',
  17. 2, ' Row-s (SS) ',
  18. 3, ' Row-x (SX) ',
  19. 4, ' Share ',
  20. 5, ' S/row-x (SSX) ',
  21. 6, ' Exclusive ',
  22. To_char (REQUEST))
  23. Mode_requested,
  24. O.owner | | '. ' | | O.object_name | | ' (' | | O.object_type | | ') '
  25. as object_name,
  26. S.type Lock_type,
  27. L.id1 Lock_id1,
  28. L.id2 Lock_id2
  29. From V$lock L, SYS. Dba_objects O, V$session S
  30. WHERE l.sid = s.sid and l.id1 = o.object_id and object_name = ' xxxx ';</pre><br>



The SQL shows the lock on all objects, if you want to find a specific object, you can filter according to the object_name field, find the corresponding SID and then check the V$session view.

This view displays the information for the session, including the terminal information, and if the terminal is found, it can be submitted or rolled back to OK. I'm here to test the environment and kill the session directly. Then modify the table to be OK.

[SQL]View PlainCopy
    1. sql>alter system kill session ' sid,serial# '

Later, the test found that the above script sometimes can not find the relevant records of the object, so added the V$access view, through the view of the object to judge, after the modified script as follows:

[SQL]View PlainCopy
  1. SELECT S.sid session_id,
  2. S.username,
  3. DECODE (Lmode,
  4. 0, ' None ',
  5. 1, ' Null ',
  6. 2, ' Row-s (SS) ',
  7. 3, ' Row-x (SX) ',
  8. 4, ' Share ',
  9. 5, ' S/row-x (SSX) ',
  10. 6, ' Exclusive ',
  11. To_char (Lmode))
  12. Mode_held,
  13. DECODE (REQUEST,
  14. 0, ' None ',
  15. 1, ' Null ',
  16. 2, ' Row-s (SS) ',
  17. 3, ' Row-x (SX) ',
  18. 4, ' Share ',
  19. 5, ' S/row-x (SSX) ',
  20. 6, ' Exclusive ',
  21. To_char (REQUEST))
  22. Mode_requested,
  23. O.owner | | '. ' | | O.object_name | | ' (' | | O.object_type | | ') '
  24. as object_name,
  25. S.type Lock_type,
  26. L.id1 Lock_id1,
  27. L.id2 Lock_id2
  28. From V$lock L, SYS. Dba_objects O, v$session s,v$access A
  29. WHERE l.sid = s.sid and l.id1 = o.object_id and s.sid=a.sid and a.object= ' proc_validate_rule_v3 ';



Once again, add the V$sql view, so that you can find the specific result of this kind of lock SQL statement, a one-time fix, SQL as follows:

[SQL]View PlainCopy
  1. /* Formatted on 2012/6/6 10:59:49 (QP5 v5.185.11230.41888) */
  2. SELECT distinct s.sid session_id,
  3. S.status,
  4. S.username,
  5. DECODE (Lmode,
  6. 0, ' None ',
  7. 1, ' Null ',
  8. 2, ' Row-s (SS) ',
  9. 3, ' Row-x (SX) ',
  10. 4, ' Share ',
  11. 5, ' S/row-x (SSX) ',
  12. 6, ' Exclusive ',
  13. To_char (Lmode))
  14. Mode_held,
  15. DECODE (REQUEST,
  16. 0, ' None ',
  17. 1, ' Null ',
  18. 2, ' Row-s (SS) ',
  19. 3, ' Row-x (SX) ',
  20. 4, ' Share ',
  21. 5, ' S/row-x (SSX) ',
  22. 6, ' Exclusive ',
  23. To_char (REQUEST))
  24. Mode_requested,
  25. O.owner | | '. ' | | O.object_name | | ' (' | | O.object_type | | ') '
  26. as object_name,
  27. S.type Lock_type,
  28. L.id1 Lock_id1,
  29. L.id2 Lock_id2,
  30. S2. Sql_text
  31. From V$lock L,
  32. SYS. Dba_objects O,
  33. V$session S,
  34. V$access A,
  35. V$sql S2
  36. WHERE l.sid = S.sid
  37. and l.id1 = o.object_id
  38. and S.sid = A.sid
  39. and S2. Hash_value = S.sql_hash_value
  40. and a.object = ' Proc_validate_rule_v3 ';

The effect is as follows:

Ext.: http://blog.csdn.net/tianlesoftware/article/details/6822321

Oracle View Object Hold lock condition

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.