抓取锁的sql语句-第四次修改
--完成情况 变量V_BLOCKING_SID 用来动态抓取 产生锁的会话id,输出参数没有任何问题,但是执行报错 标识符无效!
CREATE OR REPLACE PROCEDURE SOLVE_LOCK123
AS
V_SQL VARCHAR2(3000); --定义 v_sql 接受抓取锁的sql语句
V_SQL02 VARCHAR2(3000);
V_SQL03 VARCHAR2(3000);
KILL_SID NUMBER;
KILL_SERIAL NUMBER;
CUR_LOCK SYS_REFCURSOR; --定义游标变量,循环执行抓取锁的sql语句
CUR_LOCK02 SYS_REFCURSOR;
TYPE TP_LOCK IS RECORD( --定义 record类型的 变量
V_SID NUMBER,
V_TYPE VARCHAR2(10),
V_ID1 NUMBER,
V_ID2 NUMBER,
V_LMODE VARCHAR2(200),
V_REQUEST VARCHAR2(200),
V_LOCK_TIME NUMBER,
V_BLOCK NUMBER );
RECORDS_LOCK TP_LOCK;
TYPE TP_LOCK02 IS RECORD(
WAITING_SID NUMBER,
WAITING_SQL VARCHAR2(1000),
BLOCKER_EVENT VARCHAR2(1000),
BLOCKING_SID NUMBER,
BLOCKING_SQL VARCHAR2(1000));
RECORDS_LOCK02 TP_LOCK02;
V_BLOCKING_SID NUMBER;
V_WAITING_SID NUMBER;
BEGIN
V_SQL:='SELECT SID,TYPE,ID1,ID2,
DECODE(LMODE,0, ''NONE'',1,''NULL'', 2, ''ROW SHARE'' ,3, ''ROW EXCLUSIVE'' ,4, ''SHARE'' ,5, ''SHARE ROW EXCLUSIVE'' ,6 ,''EXCLUSIVE'' ,''HAHA'') LOCK_TYPE,
DECODE(REQUEST,0, ''NONE'',1,''NULL'', 2, ''ROW SHARE'' ,3, ''ROW EXCLUSIVE'' ,4, ''SHARE'' ,5, ''SHARE ROW EXCLUSIVE'' ,6 ,''EXCLUSIVE'' ,''HAHA'') LOCK_REQUEST,
CTIME,BLOCK FROM V$LOCK WHERE TYPE IN (''TM'',''TX'')' ;
OPEN CUR_LOCK FOR V_SQL;
LOOP
FETCH CUR_LOCK INTO RECORDS_LOCK;
EXIT WHEN CUR_LOCK%NOTFOUND;
IF RECORDS_LOCK.V_REQUEST <> 'NONE' THEN --抓取发出请求锁的会话
DBMS_OUTPUT.PUT_LINE('waiting sid: '||RECORDS_LOCK.V_SID||' is request a lock ,lock_mode is '||RECORDS_LOCK.V_REQUEST||' and being locked '|| RECORDS_LOCK.V_LOCK_TIME||'s');
V_WAITING_SID:=RECORDS_LOCK.V_SID;
END IF;
IF RECORDS_LOCK.V_BLOCK <> 0 THEN --抓取发生锁阻塞的会话
DBMS_OUTPUT.put_line('blocking sid: '||RECORDS_LOCK.V_SID||' is make a lock , lock_mode is '||RECORDS_LOCK.V_LMODE);
V_BLOCKING_SID:=RECORDS_LOCK.V_SID;
DBMS_OUTPUT.put_line(V_BLOCKING_SID);
END IF;
END LOOP;
CLOSE CUR_LOCK;
V_SQL02:='SELECT DISTINCT
WAITER.SID "WAITING_SID",
W_SQL.SQL_TEXT "SQL FROM WAITING SESSION",
BLOCKER.EVENT "BLOCKER EVENT",
BLOCKER.SID "BLOCKING SID",
B_SQL.SQL_TEXT "SQL FROM BLOCKING SESSION"
FROM V$SESSION WAITER,
V$SESSION BLOCKER,
V$SQL W_SQL,
V$SQL B_SQL
WHERE WAITER.EVENT=''enq: TX - row lock contention'' AND WAITER.BLOCKING_SESSION=BLOCKER.SID
AND W_SQL.SQL_ID=WAITER.SQL_ID
AND B_SQL.SQL_ID =NVL(BLOCKER.SQL_ID,BLOCKER.PREV_SQL_ID)';
OPEN CUR_LOCK02 FOR V_SQL02;
LOOP
FETCH CUR_LOCK02 INTO RECORDS_LOCK02;
EXIT WHEN CUR_LOCK02%NOTFOUND;
IF RECORDS_LOCK02.WAITING_SID IS NOT NULL THEN
DBMS_OUTPUT.put_line('waiting sid: '||RECORDS_LOCK02.WAITING_SID||' WAIT_SQL IS: '||RECORDS_LOCK02.WAITING_SQL);
END IF;
IF RECORDS_LOCK02.BLOCKING_SID IS NOT NULL THEN
DBMS_OUTPUT.put_line('blocking sid: '||RECORDS_LOCK02.BLOCKING_SID||' BLOCK_SQL IS: '||RECORDS_LOCK02.BLOCKING_SQL);
END IF;
END LOOP;
CLOSE CUR_LOCK02;
DBMS_OUTPUT.put_line(V_BLOCKING_SID);
-- 解决 锁阻塞、锁等待
V_SQL03:='SELECT SID , SERIAL# FROM V$SESSION WHERE SID=V_BLOCKING_SID' ;
EXECUTE IMMEDIATE V_SQL03 INTO KILL_SID,KILL_SERIAL;
--'SELECT SID ,SERIAL# FROM V$SESSION WHERE SID=197 ' into kill_sid,KILL_SERIAL;
DBMS_OUTPUT.put_line('ALTER SYSTEM KILL SESSION ('||KILL_SID||','||KILL_SERIAL||')');
END SOLVE_LOCK123;
抓取锁的sql语句-第四次修改的更多相关文章
- 抓取锁的sql语句-第七次修改
最近闲来没事,把之前写的那个抓取锁的存储过程重新修改.优化了一下,呵呵 create or replace procedure solve_lock_061203_wanjie(v_msg out v ...
- 抓取锁的sql语句-第六次修改
增加异常处理 CREATE OR REPLACE PROCEDURE SOLVE_LOCK AS V_SQL VARCHAR2(3000); --定义 v_sql 接受抓取锁的sql语句V_SQL02 ...
- 抓取锁的sql语句-第五次修改
CREATE OR REPLACE PROCEDURE SOLVE_LOCK AS V_SQL VARCHAR2(3000); --定义 v_sql 接受抓取锁的sql语句V_SQL02 VARCHA ...
- 抓取锁的sql语句-第三次修改
CREATE OR REPLACE PROCEDURE SOLVE_LOCK AS V_SQL VARCHAR2(3000); --定义 v_sql 接受抓取锁的sql语句CUR_LOCK SYS_R ...
- 抓取锁的sql语句-第二次修改
CREATE OR REPLACE PROCEDURE SOLVE_LOCK AS V_SQL VARCHAR2(3000); --定义 v_sql 接受抓取锁的sql语句 CUR_LOCK SYS ...
- 抓取锁的sql语句-第一次修改
CREATE OR REPLACE PROCEDURE SOLVE_LOCK AS V_SQL VARCHAR2(3000); CUR_LOCK SYS_REFCURSOR; TYPE TP_LOCK ...
- tcpdump来抓取执行的sql语句
# tcpdump -n -nn -tttt -i eth1 -s 65535 'port 3306' -w tcpdump_mysql.ret -C 100 一个TCP包中包含多个mysql协议包, ...
- Oracle数据库查找持有锁的SQL语句,而不是请求锁的SQL语句(原创)
Oracle数据库查找持有锁的SQL语句,而不是请求锁的SQL语句 查找活动的事务以及活动事务关联的会话信息 select s.sid 会话ID, s.serial# 会话序列号, s.usernam ...
- 数据库-SQL语句:删除和修改语句-列类型-列约束
使用MySQL客户端连接服务器的两种方式: (1)交互模式: ——查 mysql.exe -h127.0.0.1 -uroot -p mysql -uroot (2)脚本模式:——增删改 m ...
随机推荐
- Reducing the Dimensionality of data with neural networks / A fast learing algorithm for deep belief net
Deeplearning原文作者Hinton代码注解 Matlab示例代码为两部分,分别对应不同的论文: . Reducing the Dimensionality of data with neur ...
- HDOJ迷宫城堡(判断强连通 tarjan算法)
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Total Submission( ...
- (转载)php 合并数组中的数据,如果键值相等其值相加
(转载)http://hi.baidu.com/syxrrrr/item/7dfb2387343ce0874414cfdd /* * 合并数据,如果键值相等其值相加 * @param array $d ...
- UVa1658 Admiral(拆点法+最小费用流)
题目链接:http://acm.hust.edu.cn/vjudge/problem/viewProblem.action?id=51253 [思路] 固定流量的最小费用流. 拆点,将u拆分成u1和u ...
- html5---webworker多线程
javascript本身就是一个单线程的语言,一开始它的出现是为了简单的网页设计,设计者并没有考虑到多线程的问题,要知道,线程的开销是非常昂贵的.但是随着web开发的潮流化,javascript不是仅 ...
- ASP.NET MVC3 ModelState.IsValid为false的问题
模型验证通常在submit后调用Action之前进行验证,eg: public class ZhengXing { [Key] public int ZhengXin ...
- 什么是:VGA SVGA XGA SXGA
经常可以看到VGA这些专业术语,通常这些重要技术指标指的是液晶屏(TFT LCD)的分辨率. TFT是英文Thin Film Transistor的缩写,中文意思是薄膜晶体管. VGA(Video G ...
- redis学习心得之二【redis主从配置】
在前一节我们已经实践启动了一个redis服务,我们将其作为主机,现为其创建一个从机作备份使用 1.复制一份配置出来为从机所用 ~$ cp redis/etc/redis.conf ...
- Java内存管理以及各个内存区域详解
一.概述 原文链接:http://blog.csdn.net/l271640625/article/details/39761439 Java虚拟机在执行Java程序的过程中会把它所管理的内存划分为若 ...
- jEdit应用指南【基础篇】
jEdit是Java编写,强大,易用的程序员文本编辑器 jEdit是一个成熟的,设计优秀的程序员文本编辑器,已经有了7年的开发历史.在功能和易用性方面压倒许多昂贵的开发工具时,jEdit在GNU公用许 ...