当前位置: 首页 > news >正文

v$lock 查找锁 locked objects ORA-54 dblink

Database has db_link created in other databases.   这个和dblink有什么情况? 

How to find which database it is? And how to find the blocking session

 

Solution

Use the following SQL to detect the blocking session:

select SID,TYPE,ID1,ID2,LMODE,REQUEST,CTIME from v$lock l
where l.type = 'TX' or l.type = 'TM'
union
select /*+ ordered use_nl(l), use_nl(r) +*/
s.sid, r.ksqrsidt,
r.ksqrsid1, r.ksqrsid2, l.lmode, l.request,l.ctime
from v$_lock l,x$ksqrs r , v$transaction tx , v$session s
where l.raddr=r.addr
and tx.addr = l.saddr
and tx.ses_addr = s.saddr
and s.saddr = tx.ses_addr
and ( r.KSQRSIDT = 'TM' or r.KSQRSIDT = 'TX')
order by 1,2;


 select blocking_session, sid, serial#, wait_class, seconds_in_wait from v$
session
where blocking_session is not NULL order by blocking_session;

SELECT DECODE(request,0,'Holder: ','Waiter: ')||sid sess,
id1, id2, lmode, request, type
FROM V$LOCK
WHERE (id1, id2, type) IN
(SELECT id1, id2, type FROM V$LOCK WHERE request>0)
ORDER BY id1, request
/

Goal

Script and explanation for finding blocking and blocked sessions in both RAC (multi instance) and non-RAC (single instance) environments.

Solution

Purpose

Locking Mechanism

Resources (rows, tables, control files ...) represented by enqueues (TX, TM, CF, ...) can be locked in various modes (i.e. shared, exclusive, ...). Concurrent locking requests can conflict as per compatibility rules. Resources (enqueues)  are externalized via GV$RESOURCE and lock requests via GV$LOCK views. Details can be found in

     'Oracle® Database Concepts' -> chapter 'Data Concurrency and Consistency' (10.2. version)

Locking Conflict Types

  1. Local locking conflict (block) - conflicting sessions are connected to the same instance (also applies to one instance of RAC)

        Drawback: V$LOCK column BLOCK contains value 1 for blocking lock (session)

  2. Global locking conflict (block) - conflicting sessions are connected to different instances (multi instance RAC only)

        Drawback: V$LOCK column BLOCK contains value 2 to mark potential conflict (value is always 2 in RAC environments unless there is local conflict)

锁定机制

由队列(TX(事务在行上)、TM、CF 等)表示的资源(行、表、控制文件等)可以在各种模式(即共享、独占等)中锁定。并发锁定请求可能会根据兼容性规则发生冲突。资源(排队)通过 GV$RESOURCE 外部化,并通过 GV$LOCK 视图锁定请求。详情可在

“Oracle® 数据库概念”->章“数据并发性和一致性”(10.2. 版本)

锁定冲突类型

1. 本地锁定冲突(块) - 冲突会话连接到同一实例(也适用于 RAC 的一个实例(RAC one))

缺点:V$LOCK 列 BLOCK 包含用于阻塞锁(会话)的值 1

2. 全局锁定冲突(块)——冲突的会话连接到不同的实例(仅限多实例 RAC)

缺点:V$LOCK列BLOCK包含值2以标记潜在冲突(在RAC环境中,值始终为2,除非存在本地冲突)

Script Principle

Display all sessions holding or requesting lock of resource some session is waiting for. Waiting session has non-zero value of column GV$LOCK.REQUEST. Resource is identified by (TYPE,ID1,ID2 columns of GV$LOCK view).

We cannot use GV$LOCK.BLOCK in RAC as it always contains value 2 ("potential locking conflict") unless there is local conflict detected.

脚本原理

显示所有会话持有或请求某些会话正在等待的资源锁定。等待会话的列 GV$LOCK .REQUEST值为非零。请求。资源由 (GV$LOCK 视图的 TYPE,ID1,ID2 列) 标识。

我们不能使用 GV$LOCK.BLOCK,因为它始终包含值 2(“潜在的锁定冲突”),除非检测到本地冲突。

Finding root blocker

Run query provided in Script section and do one of the following.

(1) Find and kill root blockers 

   a) - Find oldest resource request - row with highest CTIME  (this is row L1)

   b) - Exists there another row with the same SID as L1?  (this is row L2 if exists)

          NOT - this is root blocker, kill it

          YES - Find row with the same values of ID1,ID2 columns as in L2 where LOCK > 0 (this is row L3)

       - Repeat (b) with L3 (L3 becomes L1) until You find root blocker

(2) Or use simple rule (may not be best) 

  a) Kill oldest blocking session (highest CTIME) 
  b) Run script again and repeat (a) until blocking session exists

寻找根阻滞剂

运行脚本部分中提供的查询,并执行以下作之一。

(1)寻找并杀死根部阻滞剂

a) - 查找最旧的资源请求 - 具有最高 CTIME 的行(这是行 L1)

b) - 存在与 L1 具有相同 SID 的另一行?(如果存在,则为第 L2 行)

不是 - 这是根阻滞剂,杀死它

YES - 查找 ID1,ID2 列值与 L2 中的值相同的行,其中 LOCK > 0(这是行 L3)

- 用 L3 重复 (b)(L3 变成 L1),直到你找到根阻滞剂

(2) 或使用简单的规则(可能不是最好的)

a) 终止最旧的阻塞会话(最高 CTIME)
b) 再次运行脚本并重复 (a) 直到阻塞会话存在

检测锁定冲突对象

通常,有问题的冲突发生在“DML 锁”(事务 - TX 和表 - TM 锁类型)上,有时找出冲突的主题(即修复应用程序设计错误以防止出现)很重要。

TM 锁的对象名称可以很容易地识别为 V$LOCK。ID1 与 DBA_OBJECTS 匹配。OBJECT_ID。

从 dba_objects o 中选择 OBJECT_ID、OWNER,OBJECT_NAME,V$LOCK l
其中 l.SID=&sid 和 l.ID1=o.OBJECT_ID;

相反,没有简单的方法(选择)来找出哪一行(TX)是等待的会话,即将TX请求与TM锁(表名)匹配。这是由于锁定实现 - 数据库块中的指针指向撤消段中分配的插槽(事务 ID - XID)。可以猜测表名(使用 CTIME 列值的相似性)。即会话正在等待 TX 锁 100 秒,并且表 A 上的 TM 锁已在 100 秒前放置(这只是一个猜测,因为 TM 锁可能已获取以在同一事务中进行早期更新)。

注意:为简单起见,GV$LOCK 被称为视图,但实际上这是视图 GV_$LOCK 的同义词(这同样适用于 V$LOCK)。

Detecting Object of Locking Conflict

Typically problematic conflicts happen with "DML Locks" (transaction - TX and table - TM lock types) and sometimes it is important to find out subject of the conflict (i.e. fix application design error to prevent issue).

Object name for TM lock can be easily identified as V$LOCK.ID1 is matching to DBA_OBJECTS.OBJECT_ID.

select OBJECT_ID, OWNER,OBJECT_NAME from dba_objects o, V$LOCK l
where l.SID=&sid and l.ID1=o.OBJECT_ID;

Contrary there is no easy way (select) to find out which row (TX) is the session waiting for i.e. to match TX request to TM lock (table name). This is due to locking implementation - pointer in database block points to assigned slot in undo segment (transaction id - XID). It is possible to make a guess of table name (using similarity of CTIME column value). I.e. session is waiting for TX lock for 100s and TM lock on table A has been placed 100s ago (this is just a guess as TM lock could have been acquired for earlier update in the same transaction).

Note: For simplicity GV$LOCK is referred as view but actually this is synonym for view GV_$LOCK (the same applies to V$LOCK).

Requirements

SQL*Plus

Configuring

There are no steps required.

Instructions

Connect as user able to select from GV$LOCK (typically user having DBA role).

sqlplus '/ as sysdba'

start <script_name>

Script 

prompt CTIME is in Seconds
set lines 120
col BLOCK for 9
col LMODE for 9
col INST_ID for 9
col REQUEST for 9
col SID for 999999
select INST_ID, SID, TYPE, ID1, ID2, LMODE, REQUEST, CTIME, BLOCK
from gv$lock where (ID1,ID2,TYPE) in
(select ID1,ID2,TYPE from gv$lock where request>0);

Sample Output

- example output showing two independent root conflicts

- there can be noted oldest conflict (sid 64 vs 38) is not the root as session 38 is blocked by session 67

INST_ID

SID

TYPE

ID1

ID2

LMODE

REQUEST

CTIME

BLOCK

------------------------------------------------------------------------------------
2212TX11141161399221603082
1248TX11141161399221063040
467TX6225949124419960262
138TX6225949124419906230
264TX131103227051406117

0

138TX1311032270514601712

26s 的锁住了171s的,期间26s还锁住了同一个sid的23s的


文章转载自:

http://0l3jsyPB.pbknh.cn
http://y0O9fPOf.pbknh.cn
http://pafKENt6.pbknh.cn
http://0uTleD8k.pbknh.cn
http://KuI8IxIl.pbknh.cn
http://IFMbV9Dm.pbknh.cn
http://nTqzZoeD.pbknh.cn
http://bexBAXEK.pbknh.cn
http://cSaNqGVd.pbknh.cn
http://1xNc8xOQ.pbknh.cn
http://DItMe0TU.pbknh.cn
http://Z8WNOLWo.pbknh.cn
http://GpkXH4CA.pbknh.cn
http://1TeJ3z51.pbknh.cn
http://9Fu20Rre.pbknh.cn
http://cJTp7LaQ.pbknh.cn
http://gmpRmz8j.pbknh.cn
http://wb1s0ruy.pbknh.cn
http://NazQCAEn.pbknh.cn
http://uhQV1Zdz.pbknh.cn
http://SBVpusAw.pbknh.cn
http://T9WIXWVx.pbknh.cn
http://zGo5hfZB.pbknh.cn
http://A0xrfvj5.pbknh.cn
http://RNRgI5Oy.pbknh.cn
http://xSLhIPyE.pbknh.cn
http://EgVoEp6F.pbknh.cn
http://nH6Bn1TB.pbknh.cn
http://n4z2XPgI.pbknh.cn
http://LUWorpEM.pbknh.cn
http://www.dtcms.com/a/372623.html

相关文章:

  • Daily算法刷题【面试经典150题-2️⃣】
  • Ucloud技术支持问题
  • 调试 cuda kernel
  • OpenLayers常用控件 -- 章节九:比例尺控件教程
  • 李沐深度学习论文精读(一)AlexNet + ResNet
  • CMake构建C++项目,报错“CMake Error CMAKE_C_COMPILER not set, after EnableLanguage”
  • 2025最新超详细FreeRTOS入门教程:第五章 FreeRTOS信号量
  • 安卓逆向(二)相关问题及解决方案
  • 自学嵌入式第37天:MQTT协议
  • daily notes[11]
  • Qt中QProxyStyledrawControl函数4个参数的意义
  • AutoHotkey识别图片
  • 【数学建模】在烟雾导弹遮蔽模型中的实际参考文献
  • 快速了解word2vec模型
  • 关于高并发的一连串问题分析(未完成)
  • Ansible Playbook 核心配置实操指南:主机清单引用、并行执行与模块化组织
  • 2025年金融专业人士职业认证发展路径分析
  • NVM 使用指南(Node Version Manager)
  • 2025年体制内职业发展相关认证选择指南
  • 电脑提速之关于Edge优化
  • 图像纹理相似度评价——Gabor变换
  • [光学原理与应用-463]:波动光学 - AOM的0级光与1级光
  • SpringBoot 公共字段自动填充
  • 《计算》第一二章读书笔记
  • 多模态大模型---第1节
  • 删除字符串中的空格
  • STM32 开发(三十三)STM32F103 片内资源 —— 直接存储 DMA 实战 编码详解
  • MGSM:大模型多语言数学推理的“试金石”
  • 卫星直连服务:从稀疏星座到全球覆盖的未来通信革命
  • FastAPI:像搭建餐厅一样设计API