Data Concurrent Experiment(Lock conflict)

There's a stage as below:

There are 2 users ngreenberg and smavris,operating at the same time.Smavris' session seems stuck.


All Commands are as below (in the order of time):

ngreenberg)

SQL> show user
USER is "NGREENBERG"
SQL> update hr.employees set phone_number='650.555.1212' where employee_id = 110 ;
1 row updated.

smavris)

SQL> show user
USER is "SMAVRIS"
SQL> update hr.employees set phone_number='650.555.1212' whereemployee_id = 110 ;
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                     
......(it seems out of response)


Analyzation:

This is an ordinary problem of lock confliction.The user ngreenberg got the row-based lock in DML.But the lock cannot be released until ngreenberg committed the transaction.In a result,other users' transaction which manipulated that row would be stuck.


Information about lock confliction:

session)

select SID,SESS_SERIAL#,BLOCKER_SID,BLOCKER_SESS_SERIAL#,WAIT_EVENT_TEXT FROM V$SESSION_BLOCKERS;

NOTE:

"SID,SESS_SERIAL#" is information about session which is blocked.

"BLOCKER_SID,BLOCKER_SESS_SERIAL#" is information about session which is blocking.

"WAIT_EVENT_TEXT" is information about reason of the confliction.


relevant OS process)

CREATE VIEW S_P AS (SELECT S.SID,S.SERIAL#,S.USERNAME,P.SPID FROM V$SESSION S,V$PROCESS WHERE S.ADDR=P.PADDR)
SELECT USERNAME BLOCKER_DB_USNAME,SPID BLOCKER_OS_PID FROM S_P WHERE SID=[BLOCKER_SID] AND SERIAL#=[BLOCKER_SESS_SERIAL#]
SELECT USERNAME BLOCKEE_DB_USNAME,SPID BLOCKEE_OS_PID FROM S_P WHERE SID=[BLOCKEE_SID] AND SERIAL#=[BLOCKEE_SESS_SERIAL#]

NOTE:

refer "V$SESSION" for session information.

refer "V$PROCESS" for process information.


relevant SQL commands)

As to blocker,there's no sql executed now.So last sql text is the key information.

SELECT PREV_SQL_ID FROM V$SESSION WHERE SID=[XX] AND SERIAL#=[XXXX];
SELECT SQL_TEXT FROM V$SQLTEXT WHERE SQL_ID='XXXXXXXXXXXXX';

As to blockee,we refer the current sql executed.

SELECT SQL_ID FROM V$SESSION WHERE SID=[XX] AND SERIAL#=[XXXX];
SELECT SQL_TEXT FROM V$SQLTEXT WHERE SQL_ID='XXXXXXXXXXXXX';


release the lock)

normal way:the transaction which is blocking is ended by 'rollback' or 'commit'.

killing the blocker session:ALTER SYSTEM KILL SESSION 'SID,SERIAL#' IMMEDIATE;

killing the blocker server process:EXECUTE "KILL -9 [PID]" ON OS

HINTS:the transaction which is terminated abnormally will be rollbacked.

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章