Oracle阻塞阻塞(blockingblocked)实例详解实例详解
一、概述:
阻塞是DBA经常碰到的情形,尤其是不良的应用程序设计所造成的阻塞将导致数据库性能的严重下降,直至数据库崩溃。对
DBA而言,有必要知道如何定位到当前系统有哪些阻塞,到底谁是阻塞者,谁是被阻塞者。本文对此给出了描述并做了相关
演示。
二、演示阻塞:
--更新表,注,提示符scott@CNMMBO表明用户为scott的session,用户名不同,session不同。
scott@CNMMBO> update emp set sal=sal*1.1 where empno=7788;
1 row updated.
scott@CNMMBO> @my_env
SPID SID SERIAL# USERNAME PROGRAM
------------ ---------- ---------- --------------- ------------------------------------------------
11205 1073 4642 robin oracle@SZDB (TNS V1-V3)
--另起两个session更新同样的行,这两个session都会处于等待,直到第一个session提交或回滚
leshami@CNMMBO> update scott.emp set sal=sal+100 where empno=7788;
goex_admin@CNMMBO> update scott.emp set sal=sal-50 where empno=7788;
--下面在第一个session 查询阻塞情况
scott@CNMMBO> @blocker
BLOCK_MSG BLOCK
-------------------------------------------------- ----------
pts/5 ('1073,4642') is blocking 1067,10438 1
pts/5 ('1073,4642') is blocking 1065,4464 1
--上面的结果表明session 1073,4642 阻塞了后面的2个
--即session 1073,4642是阻塞者,后面2个session是被阻塞者
--Author : Leshami
--Blog : http://blog.csdn.net/leshami
--下面查询正在阻塞的session id,SQL语句以及被阻塞的时间
scott@CNMMBO> @blocking_session_detail.sql
'SID='||A.SID||'WAITCLASS='||A.WAIT_CLASS||'TIME='||A.SECONDS_IN_WAIT||CHR(10)||'QUERY='||B.SQL_TEXT
------------------------------------------------------------------------
sid=1067 Wait Class=Application Time=5995
Query=update scott.emp set sal=sal+100 where empno=7788
sid=1065 Wait Class=Application Time=225
Query=update scott.emp set sal=sal-50 where empno=7788
--下面的查询阻塞时锁的持有情况
scott@CNMMBO> @request_lock_type
USERNAME SID TY LMODE REQUEST ID1 ID2
------------------------------ ---------- -- ----------- ----------- ---------- ----------
SCOTT 1073 TX Exclusive None 524319 27412
LESHAMI 1067 TX None Exclusive 524319 27412
GOEX_ADMIN 1065 TX None Exclusive 524319 27412
--可以看到LESHAMI,GOEX_ADMIN 2个用户都在请求524319/27412上的Exclusive锁,而此时已经被SCOTT加了Exclusive
锁
--查询阻塞时锁的持有详细信息
scott@CNMMBO> @request_lock_detail
SID USERNAME OSUSER TERMINAL OBJECT_NAME TY Lock Mode Req_Mode
---------- -------------------- --------------- ------------------------- -------------------- -- ----------- --------------------
1065 GOEX_ADMIN robin pts/1 EMP TM Row Excl
1065 GOEX_ADMIN robin pts/1 Trans-524319 TX --Waiting-- Exclusive
1067 LESHAMI robin pts/0 EMP TM Row Excl
1067 LESHAMI robin pts/0 Trans-524319 TX --Waiting-- Exclusive
1073 SCOTT robin pts/5 EMP TM Row Excl
1073 SCOTT robin pts/5 Trans-524319 TX Exclusive
评论0
最新资源