How To Resolve Database Blocking In Oracle
Database blocking is a situation where the statement run by one user locks a record or set of records and another statement run by the same user or different user requires a conflicting lock type on the record or records, locked by the first user.
Database blocking issue is a very common scenario in any application.
How to identify the blocking session? Or more specifically how to identify the blocking
rows and objects? How to resolve database blocking issue? Let’s see one by one.
How to Identify the blocking session
1. DBA_BLOCKERS : Gives information only about the blocking session.
HOLDING_SESSION
—————
252
SQL> select l1.sid, ‘IS BLOCKING’, l2.sid
from v$lock l1, v$lock l2
where l1.block =1 and l2.request > 0
and l1.id1=l2.id1
and l1.id2=l2.id2
/
SID ‘ISBLOCKING’ SID
———- ————- ———-
244 IS BLOCKING 252
|| ‘ ( SID=’ || s1.sid || ‘ ) is blocking ‘
|| s2.username || ‘@’|| s2.machine || ‘ ( SID=’ || s2.sid || ‘ ) ‘ AS blocking_status
from v$lock l1, v$session s1, v$lock l2, v$session s2
where s1.sid=l1.sid and s2.sid=l2.sid
and l1.BLOCK=1 and l2.request > 0
and l1.id1 = l2.id1
and l2.id2 = l2.id2 ;
BLOCKING_STATUS
——————————————————————————–
PK@host1( SID=244 ) is blocking PY@Host2)
ADDR KADDR SID TY ID1 ID2 LMODE
REQUEST CTIME BLOCK
—————- —————- ———- – ———- ———- ——- ———-
———- ———-
0000000451723DE8 0000000451723E20 244 TX 1310745 3139497
6 0 166 1
000000046032AFE0 000000046032B000 252 TX 1310745 3139497
0 6 33 0
TYPES OF LOCKS – UL, TX amd TM
changes data. Number of objects are being changed does not matter. The ID1 and ID2
columns point to the rollback segment and transaction table entries for that transaction.
ID1 column identifies the object being modified.
So to find the object that is being blocked we can use ID1 from the v$lock.
OBJECT_NAME
————–
OBJ1
row_wait_obj#, do.data_object_id, row_wait_file#, row_wait_block#, row_wait_row#,
dbms_rowid.rowid_create ( 1, do.data_object_id, ROW_WAIT_FILE#,
ROW_WAIT_BLOCK#, ROW_WAIT_ROW# )
from v$session s, dba_objects do
where sid=252
and s.ROW_WAIT_OBJ# = do.OBJECT_ID ;
——————————————————————————–
ROW_WAIT_OBJ# DATA_OBJECT_ID ROW_WAIT_FILE# ROW_WAIT_BLOCK#
ROW_WAIT_ROW#
————- ————– ————– ————— ————-
DBMS_ROWID.ROWID_C
——————
307193 307193 5 455 0
AABK/5AAFAAAAHHAAA
where q.address = s.sql_address
and s.sid = 252;
—– —————————————————————-
252 update obj1 set bar=:”SYS_B_0″ where bar=:”SYS_B_1″
v$session where blocking_session is not NULL order by blocking_session;
—————- ———- ———- ————————————————–
244 252 11049 Application 1634
System altered.