当前位置:网站首页>模拟Oracle锁等待与手工解锁
模拟Oracle锁等待与手工解锁
2022-06-11 19:54:00 【huryer】
模拟Oracle锁等待与手工解锁
1、用途
本文描述在Oracle数据库发生锁等待时,如果查看锁信息,以及如何解锁。
2、模拟过程
2.1、创建测试表
-- 第1个程序 ---------------------------------------------
-- 创建测试表
CREATE TABLE t1(
id INT,
name VARCHAR(10)
)
;
-- 写入测试数据,并提交
DELETE FROM t1;
insert into t1(id,name) values(1,'a');
insert into t1(id,name) values(2,'b');
commit;
2.2、模拟锁等待
-- 第1个sqlplus程序 ---------------------------------------------
-- 查看当前session,并更新数据:
select userenv('sid') from dual;
update t1 set name = 'a1' where id = 1;
-- 第2个sqlplus程序 ---------------------------------------------
-- 再打开一个sqlplus程序,执行sql,此时处于阻塞状态
select userenv('sid') from dual;
update t1 set name = 'a2' where id = 1;
2.3、分析锁等待
-- 第3个程序 ---------------------------------------------
--查看锁定进程sql语句
select distinct s.sid
, s.serial#
, s.blocking_session /*当前被哪个sid阻塞*/
, s.client_info /*客户端信息(ip)*/
, s.machine /*主机名称*/
, s.osuser /*操作系统用户*/
, s.program /*程序名称*/
, s.seconds_in_wait /*等待时长(秒)*/
, s.event /*事件*/
, s.status /*状态*/
, s.wait_class /*等待类*/
, lo.oracle_username /*oracle用户*/
, lo.locked_mode /*锁定模式*/
, ao.object_name /*锁定的对象*/
, s1.sql_text as sql_current /*当前执行的sql*/
, s2.sql_text as sql_previous /*前一个执行的sql*/
from v$locked_object lo
, dba_objects ao
, v$session s
left join v$sql s1 on s1.sql_id = s.sql_id
left join v$sql s2 on s2.sql_id = s.prev_sql_id
where ao.object_id = lo.object_id
and lo.session_id = s.sid
;
锁等待情况如下图所示:
2.4、解除锁等待
可以通过以下2种方式进行锁处理
1、提交或回滚第1个程序
commit;
rollback;
2、手工结束第1个session
alter system kill session 'sid,serial#';
观察第2个程序可以继续执行。
2.5、小结
本文仅用于模拟锁等待的发生与解锁过程。实际项目中,可以通过sql查询锁等待列表,导出问题数据,并及时解锁,事后再进行问题分析。
边栏推荐
- LNMP架构源码编译安装图文讲解(附带搭建论坛实验)
- 【求助】请问如何让微信公众号文章在外部浏览器中打开后还能显示下方的精选留言?
- dried food! Information diffusion prediction based on sequence hypergraph neural network
- Hdu3527 (Hangdian) spy problem
- A brief talk on shutter button
- 接口隔离原则
- 无监督图像分类《SCAN:Learning to Classify Images without》代码分析笔记(1):simclr
- Explanation of LNMP architecture source code compilation and installation with pictures and texts (with forum experiment)
- Unified exception handling
- 556. next larger element iii- (31. next permutation) - two iterations
猜你喜欢

Shanghai internal promotion 𞓜 Yuyang teacher's research group of Shanghai Chizhi research institute recruits full-time researchers

全名单!2022泰晤士亚洲大学排名公布!

Calculate the number of 926 in the string to the power of 9260 of 926

dried food! Information diffusion prediction based on sequence hypergraph neural network

Picture bed: picgo+ Tencent cloud +typera

Are there any techniques for 3D modeling?

3D建模有什么技巧吗?

"Video version Mae" of hekaiming team, efficient video pre training! The effect is also very good when mask ratio is up to 90

Yolov3 pytoch code and principle analysis (II): network structure and loss calculation

Usage of duck beak wire stripper
随机推荐
Poj1028 web navigation
These postgraduate entrance examination majors are easy to be confused. If you make a mistake, you will take the exam in vain!
导师转我800块,让我仿真一个电路(电源设计)
Introduction to typescript
The principle that the picture of QQ Post Bar changes when it is opened
计算926的9260次方里的字符串里有多少个926
Unsupervised image classification code analysis notes of scan:learning to classify images without (1): simclr
556. next larger element iii- (31. next permutation) - two iterations
STC 纯硬件自动下载电路 V2
模块八作业
YOLOv3 Pytorch代码及原理分析(二):网络结构和 Loss 计算
Experiment report of basic mechanical experiment (II) of School of distance and continuing education, Dalian University of technology [standard answer]
VS2010 cannot open when linking sql2008 database
AHB2APB_ Bridge design
The tutor transferred me 800 yuan and asked me to simulate a circuit (power supply design)
何恺明团队的“视频版本MAE”,高效视频预训练!Mask Ratio高达90%时效果也很好!...
This article introduces you to the infrastructure of sofaregistry
RTL仲裁器设计
[advanced MySQL] differences among 10 data types and how to optimize the table structure (3)
管理者必须知道的三个常识