Oracle死锁一例(ORA-00060),锁表导致的业务死锁问题
1、问题发现
检查客户数据库的时候发现存在大量死锁的情况
Thread advanced to log sequence (LGWR switch)
Current log# seq# mem# : /oradata/oracle/online_log/redo16_01.log
Current log# seq# mem# : /oradata/oracle/online_log/redo16_02.log
Tue Jul ::
Archived Log entry added for thread sequence ID 0x59dc8ffa dest :
Tue Jul ::
LNS: Standby redo logfile selected for thread sequence for destination LOG_ARCHIVE_DEST_2
Tue Jul ::
opiodr aborting process unknown ospid () as a result of ORA-
Tue Jul ::
ORA-: Deadlock detected. More info in file /u01/oracle/diag/rdbms/orcl/orcl/trace/orcl_ora_25846.trc.
Tue Jul ::
ORA-: Deadlock detected. More info in file /u01/oracle/diag/rdbms/orcl/orcl/trace/orcl_ora_14067.trc.
Tue Jul ::
ORA-: Deadlock detected. More info in file /u01/oracle/diag/rdbms/orcl/orcl/trace/orcl_ora_20781.trc.
Tue Jul ::
Thread cannot allocate new log, sequence
Private strand flush not complete
查看trace文件orcl_ora_25846.trc结果如下
Deadlock graph:
---------Blocker(s)-------- ---------Waiter(s)---------
Resource Name process session holds waits process session holds waits
TX-026e0020-000001a5 X S
TM-0007fd6c- X SX session : DID --000001FEsession : DID --
session : DID --00000014session : DID --000001FE Rows waited on:
Session : obj - rowid = 0007FD6C - AAAAAAAAAAAAAAAAAA
(dictionary objn - , file - , block - , slot - )
Session : no row ----- Information for the OTHER waiting sessions -----
Session :
sid: ser: audsid: user: /FD14
flags: (0x45) USR/- flags_idl: (0x1) BSY/-/-/-/-/-
flags2: (0x40009) -/-/INC
pid: O/S info: user: oracle, term: UNKNOWN, ospid:
image: oracle@dbserver1
client details:
O/S info: user: TL3050, term: TL3050-WZ, ospid: :
machine: WORKGROUP\TL3050-WZ program: CWV4.2.8.337_20131204.exe
application name: CWV4.2.8.337_20131204.exe, hash value=
current SQL:
insert into pzd2018
(UNI_NO,ORD,STYPE,STYPE2,SNO,SYEAR,SMONTH,RMONTH,SDAY,SABSTRACT,OPERATOR,J_AMOUNT,D_AMOUNT,SUBJ,SUBJNAME,
OPP_SUBJ,SRC_CODE,ECO_CODE,SRC_PAYTYPE,SRC_BUTYPE,ECO_TYPE,ECO_WARRANT,PRJ_ORDER,PRJ_NAME,OPP_PRJ,CLR_ORDER,
UNIT_CODE,SPECCODE,CONTRACT_NO,CAR_NO,OLPAY_SNO,schedule_date,WB_TYPE,WB_JNUM,WB_DNUM,WB_FACT,NUM_TYPE,
NUM_JNUM,NUM_DNUM,NUM_PRICE,CAP_NO,CAP_ORD,JSFS_CODE,ZPH,BUSS_DATE,OTHER_UNIT,ACNT,BANKNO,ADDRESS1,ADDRESS2,
TNO,ACT_NO,BU_CODE,T_CODE,RESBU_CODE,RESBU_AMT,SPECCODE1,SPECCODE2,SPECCODE3,SPECCODE4,RES_S1,
RES_S2,RES_S3,RES_S4,ASSET_SUBJ,TAX_NO,SRC_NAME,ADDITION,UNI_PRJ_ORDER,Clr_Bu_Code,
Source_Type,Source,SrKey,SMark,Uni_Prj_Name,clrsno,input_name,check_name,attach_act,
attach_act_no,pz_attr,src_type,zj_type,ref_uni_no,charge_sno,charge_name,src_lkx,order_type,c ----- End of information for the OTHER waiting sessions ----- Information for THIS session: ----- Current SQL Statement for this session (sql_id=9ktt36bsngnyx) -----
insert into pz2018
(UNI_NO,STYPE,STYPE2,SNO,SYEAR,SMONTH,RMONTH,SDAY,INPUT_NAME,CHECK_NAME,COMP_NAME,COMP_NAME2,
ADDITION,CHILDNUM,J_AMOUNT,D_AMOUNT,SSTATE,REMARK,PZ_ATTR)
values(:,:,:,:,:,:,:,:,:,:,:,:,:,:,:,:,:,:,:)
===================================================
2、问题分析
可以看出来241号会话持有一个TM锁,在执行insert into pzd2018语句在等待S锁
4468号会话持有一个TX锁,在执行insert into pz2018语句,在等待SX锁
通过与业务沟通与数据库查询发现了以下的锁表操作,并和业务确定了属于业务SQL
lock table pz2018 in exclusive mode
到这里问题已经清楚了,整个逻辑是这样的
241号会话将pz2018全表排他模式进行了锁定,导致4468会话无法对pz2018表进行insert操作,原因是无法在表上获取共享排它锁即SX锁,导致4468号会话进入等待模式
而4468号会话在等待前进行了insert into pzd2018操作,而241号会话在插入时存在唯一约束,导致241会话进行TX锁等待,等待4468号session数据提交或者回滚
这样一个环状等待就形成了即死锁
等待发生时会话的等待情况
SQL> select a.sample_time,
2 a.session_id,
3 a.session_serial#,
4 a.blocking_session bsession,
5 a.blocking_session_serial# bserial#,
6 a.event,
7 a.machine,
8 a.module,
9 a.sql_opname
10 from dba_hist_active_sess_history a
11 where a.session_id in (241, 4468, 6819, 10817)
12 and a.sample_time > to_date('', 'yyyymmddhh24')
13 and a.sample_time < to_date('', 'yyyymmddhh24')
14 and a.event is not null
15 order by a.sample_time
16 ;
SAMPLE_TIME SESSION_ID SESSION_SERIAL# BSESSION BSERIAL# EVENT MACHINE MODULE SQL_OPNAME
------------------------------ ---------- --------------- ---------- ---------- ------------------------------ ------------------------------ ------------------------------ ----------------------------------------------------------------
03-7月 -18 10.00.40.857 上午 241 425 6587 7875 enq: TM - contention WORKGROUP\TL3050-WZ CWV4.2.8.337_20131204.exe LOCK TABLE
03-7月 -18 10.49.45.384 上午 10817 97 12929 7665 read by other session webserver JDBC Thin Client SELECT
03-7月 -18 10.51.16.143 上午 241 425 4468 2029 enq: TX - row lock contention WORKGROUP\TL3050-WZ CWV4.2.8.337_20131204.exe INSERT
03-7月 -18 10.51.16.143 上午 4468 2029 241 425 enq: TM - contention ZDCW\WANGH88208561 XCV5(新5.24).exe INSERT
03-7月 -18 10.52.46.903 上午 10817 121 null event dbserver1 SELECT
03-7月 -18 10.53.57.464 上午 6819 99 10817 133 enq: TX - row lock contention ZDCW\WANGWD88981612 CWV4.exe INSERT
03-7月 -18 10.53.57.464 上午 10817 133 6819 99 enq: TM - contention ZDCW\WANGH88208561 XCV5(新5.24).exe INSERT
03-7月 -18 10.54.07.554 上午 10817 133 db file parallel read ZDCW\WANGH88208561 XCV5(新5.24).exe INSERT
8 rows selected
3、锁等待的模拟,问题复现
---session1
SQL> lock table pz2018 in exclusive mode;
Table(s) Locked.
----session2
SQL> insert into pzd2018(OBJECT_ID,OBJECT_NAME) values(100000000,'PZD_Yong');
1 row created.
SQL> insert into pz2018(OBJECT_ID,OBJECT_NAME) values(100000000,'PZ_Yong');
----session2执行直接hang住无法完成,在等待TM锁
SQL> select s.SID,s.BLOCKING_SESSION bsid,s.EVENT,s.MACHINE,s.MODULE,s.STATUS,s.STATE from v$session s where s.EVENT is not null and s.STATUS='ACTIVE' and s.WAIT_CLASS<>'Idle';
SID BSID EVENT MACHINE MODULE STATUS STATE
---------- ---------- ------------------------------ ------------------------------ ---------------------------------------- -------- -------------------
17 143 enq: TM - contention 172-16-8-110 SQL*Plus ACTIVE WAITING
----session1执行
SQL> insert into pzd2018(OBJECT_ID,OBJECT_NAME) values(100000000,'PZD_Yong');
--session1 直接hang住,session2抛出错误发现死锁
SQL> insert into pz2018(OBJECT_ID,OBJECT_NAME) values(100000000,'PZ_Yong');
insert into pz2018(OBJECT_ID,OBJECT_NAME) values(100000000,'PZ_Yong')
*
ERROR at line 1:
ORA-00060: deadlock detected while waiting for resource
----检查数据库等待
SQL> set linesize 1000 pagesize 5000
SQL> col EVENT for a30
SQL> col MACHINE for a30
SQL> col MODULE for a40
SQL> select s.SID,s.BLOCKING_SESSION bsid,s.EVENT,s.MACHINE,s.MODULE,s.STATUS,s.STATE from v$session s where s.EVENT is not null and s.STATUS='ACTIVE' and s.WAIT_CLASS<>'Idle';
SID BSID EVENT MACHINE MODULE STATUS STATE
---------- ---------- ------------------------------ ------------------------------ ---------------------------------------- -------- -------------------
143 17 enq: TX - row lock contention 172-16-8-110 SQL*Plus
查看数据库alert日志发现
Thu Jul 05 11:40:40 2018
ORA-00060: Deadlock detected. More info in file /u01/app/oracle/diag/rdbms/dtstack1/dtstack1/trace/dtstack1_ora_29840.trc.
查看死锁trace
Deadlock graph:
---------Blocker(s)-------- ---------Waiter(s)---------
Resource Name process session holds waits process session holds waits
TM-0001554c-00000000 28 17 X 27 143 SX
TX-00040008-000002d9 27 143 X 28 17 S session 17: DID 0001-001C-00000024 session 143: DID 0001-001B-00000155
session 143: DID 0001-001B-00000155 session 17: DID 0001-001C-00000024 Rows waited on:
Session 17: no row
Session 143: obj - rowid = 0001554C - AAAAAAAAAAAAAAAAAA
(dictionary objn - 87372, file - 0, block - 0, slot - 0) ----- Information for the OTHER waiting sessions -----
Session 143:
sid: 143 ser: 905 audsid: 610017 user: 85/DTYONG
flags: (0x45) USR/- flags_idl: (0x1) BSY/-/-/-/-/-
flags2: (0x40009) -/-/INC
pid: 27 O/S info: user: oracle, term: UNKNOWN, ospid: 29846
image: oracle@172-16-8-110 (TNS V1-V3)
client details:
O/S info: user: oracle, term: pts/1, ospid: 29845
machine: 172-16-8-110 program: sqlplus@172-16-8-110 (TNS V1-V3)
application name: SQL*Plus, hash value=3669949024
current SQL:
insert into pz2018(OBJECT_ID,OBJECT_NAME) values(100000000,'PZ_Yong') ----- End of information for the OTHER waiting sessions ----- Information for THIS session: ----- Current SQL Statement for this session (sql_id=7jbgf8fc4cac0) -----
insert into pzd2018(OBJECT_ID,OBJECT_NAME) values(100000000,'PZD_Yong')
===================================================
PROCESS STATE
-------------
Process global information:
process: 0x914c4ed0, call: 0x910d2008, xact: 0x90390710, curses: 0x916aa020, usrses: 0x916aa020
in_exception_handler: no
----------------------------------------
SO: 0x914c4ed0, type: 2, owner: (nil), flag: INIT/-/-/0x00 if: 0x3 c: 0x3
proc=0x914c4ed0, name=process, file=ksu.h LINE:12721, pg=0
(process) Oracle pid:28, ser:23, calls cur/top: 0x910d2008/0x910d2008
flags : (0x0) -
flags2: (0x0), flags3: (0x10)
intr error: 0, call error: 0, sess error: 0, txn error 0
intr queue: empty
ksudlp FALSE at location: 0
(post info) last post received: 138 0 2
last post received-location: ksl2.h LINE:2374 ID:kslpsr
last process to post me: 0x914b3298 1 6
last post sent: 0 0 26
last post sent-location: ksa2.h LINE:285 ID:ksasnd
last process posted by me: 0x914b3298 1 6
(latch info) wait_event=0 bits=0x0
Process Group: DEFAULT, pseudo proc: 0x915515e8
O/S info: user: oracle, term: UNKNOWN, ospid: 29840
OSD pid info: Unix process pid: 29840, image: oracle@172-16-8-110 (TNS V1-V3)
----------------------------------------
SO: 0x916aa020, type: 4, owner: 0x914c4ed0, flag: INIT/-/-/0x00 if: 0x3 c: 0x3
proc=0x914c4ed0, name=session, file=ksu.h LINE:12729, pg=0
(session) sid: 17 ser: 683 trans: 0x90390710, creator: 0x914c4ed0
flags: (0x45) USR/- flags_idl: (0x1) BSY/-/-/-/-/-
flags2: (0x40009) -/-/INC
Oracle死锁一例(ORA-00060),锁表导致的业务死锁问题的更多相关文章
- 查看oracle的sql语句历史记录和锁表的情况
查看oracle的sql语句历史记录和锁表的情况 (2012-01-04 20:59:59) 转载▼ 标签: 杂谈 分类: database 查询sql的历史记录 select * from v$sq ...
- oracle 锁表的处理。
最近系统每天经常锁表,进程杀死后,很快再次锁住这个表. (一)先贴出现场处理死锁的步骤. 另外:有时候通过PL/SQL执行kill session可能仍然无法解锁,此时需要登陆到Oracle服务器将进 ...
- oracle 查看锁表情况并处理锁表
/* *locked *query locked object and analyse reason,kill it * */ select 'alter system kill session '' ...
- oracle锁表查询,资源占用,连接会话,低效SQL等性能检查
查询oracle用户名,机器名,锁表对象 select l.session_id sid, s.serial#, l.locked_mode, l.oracle_username, l.os_user ...
- informix 数据库锁表分析和解决方法
一.前言 在联机事务处理(OLTP)的数据库应用系统中,多用户.多任务的并发性是系统最重要的技术指标之一.为了提高并发性,目前大部分RDBMS都采用加锁技术.然而由于现实环境的复杂性,使用加锁技术又不 ...
- 针对MyISAM锁表的解决方案
最近服务器上经常出现mysql进程占CPU100%的情况,使用show processlist命令后,看到出现了很多状态为LOCKED的sql.使用show status like 'table%'检 ...
- ORACLE查询数据库的锁表情况
查询数据库的锁表情况语句如下: SELECT p.spid,a.serial#, c.object_name,b.session_id,b.oracle_username,b.os_user_na ...
- Java并发 行级锁/字段锁/表级锁 乐观锁/悲观锁 共享锁/排他锁 死锁
原文地址:https://my.oschina.net/oosc/blog/1620279 前言 锁是防止在两个事务操作同一个数据源(表或行)时交互破坏数据的一种机制. 数据库采用封锁技术保证并发操作 ...
- Oracle锁表与解锁
查看锁表语句:方法1: select sess.sid, sess.serial#, lo.oracle_username, lo.o ...
随机推荐
- js对象之间的继承
js的对象之间的继承抛弃了原型与构造器的概念,而转为字面量对象之间进行属性拷贝的方式进行继承. 首先我们来写一个封装好的继承函数: function extend(parent){ var child ...
- COGS2216 你猜是不是KMP
第一道自己写的FFT...... 不知为啥这题在网上找不到题解......真是麻烦,害得我推了半天...... 还是写个简要题解吧...... 首先把S和T拆成序列,a~z分别对应成1~26,?是0, ...
- sass判断语句
@if判断 @if可一个条件单独使用,也可以和@else结合多条件使用 scss.style css.style 三目判断 语法为:if($condition, $if_true, $if_false ...
- chengfa
public class ddddd{ public static void main(String[] args) { ; ; i <= m; i++) { ; j <= i; j++) ...
- 第4课 简易浏览器-WebViewer组件的使用方法
做一个手机浏览器,需要哪些组件呢? 一.组件设计 二.组件属性及命名修改 三.逻辑设计 1.导航按钮代码:前进.后退.主页 2.访问网页按钮 1)根据用户在地址栏输入的地址书写,判断书写中是否含有“h ...
- 求n的元素的最大最小值
public static int[] maxMin(int a[]) { int[] res = new int[2]; int len = a.length; if (len <= 0) { ...
- 使用DIDatepicker
使用DIDatepicker https://github.com/noxt/DIDatepicker 效果: #import "DIViewController.h" #impo ...
- 设计模式:组合(Composite)模式
设计模式:组合(Composite)模式 一.前言 关于Composite模式,其实就是组合模式,又叫部分整体模式,这个模式在我们的生活中也经常使用,比如说如果读者有使用Java的GUI编写过程序 ...
- CentOS 系统新装每次必看,直到背下。。
1.CentOS7 mini 修改网卡信息: vi /etc/sysconfig/network-scripts/ifcfg-ens192 ONBOOT = yes vi /etc/resolv.co ...
- PTA练习题之7-1 矩阵转置(10 分)
7-1 矩阵转置(10 分) 将一个3×3矩阵转置(即行和列互换). 输入格式: 在一行中输入9个小于100的整数,其间各以一个空格间隔. 输出格式: 输出3行3列的二维数组,每个数据输出占4列. 输 ...