Diagnose blocked sessions in Oracle

Source: Internet
Author: User

Due to the lock mechanism, when execution of a DML or ddl SQL statement is blocked, you need to find out why the SQL statement is blocked. The following describes the common diagnostic methods:

Suppose there is a table: table t (id int primary key, val int); Data is:

Id Val
1 1
2 2

1. In A Session, Session A is called here, and the following update statement is executed, not submitted or rolled back.
SQL> update t set val = 3 where id = 1;

2. In another Session, Session B is called Session B and the following update statement is executed. Session B will be blocked.

SQL> update t set val = 4 where id = 1;

However, when an active transaction locks an object, there will be records such as object_id and session_id in the v $ locked_object view. The XIDUSN, XIDSLOT, and XIDSQN fields of blocked sessions are usually empty. the session whose session_id is 139 is blocked.


Select dbo. * from v $ locked_object lo, dba_objects dbo where lo. object_id = dbo. object_id and lo. xidusn = 0

By querying v $ lock, you can see which session is blocked and which session: 142 is blocked by 139.

With blkedsess as (select * from v $ lock where request! = 0)
Select blkingsess. sid blockingsid, blkedsess. sid blockedsid
From v $ lock blkingsess, blkedsess
Where blkingsess. id1 = blkedsess. id1
And blkingsess. id2 = blkedsess. id2
And blkingsess. sid! = Blkedsess. sid


You can view session-related information through v $ session. The blocked status is generally ACTIVE. You can also use SQL _address and v $ SQL to find the blocked SQL statement.

Select sid, serial #, status, SQL _address from v $ session where sid in (139,142)


Select * from V $ SQL where address = '6be7d33c'


At this time, the DBA can contact the blocked session to end the transaction or use the command to terminate the session as needed.

Alter system kill session '2017, 7'; where 142 is sid and 7 is serial #

Session 142 will receive the following error, and session139 will proceed to the subsequent steps.

ERROR:
ORA-03114: not connected to Oracle

For more information about Oracle, see Oracle topics page http://www.bkjia.com/topicnews.aspx? Tid = 12

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.