OSCAR数据库上锁问题如何排查

关键字

oscar lock

问题描述

oscar 数据库上锁问题如何排查

解决问题思路

准备数据
create table lock_test(name varchar(10),age varchar(10));

insert into lock_test values('ff','10');
insert into lock_test values('yy','20');
insert into lock_test values('ll','30');


session1:
begin;
update lock_test set age = 'session1' where name = 'ff';

session2:
begin;
update lock_test set age = 'session2' where name = 'ff';

session2 因为更新同一行数据肯定 pending



-- 查询阻塞PID及SQL
SELECT a.SID,a.STATUS,a.BLOCKING_SESSION,a.EVENT,a.CURRENT_SQL,a.PREV_SQL ,b.CURRENT_SQL AS BLOCK_CURRENT_SQL, b.PREV_SQL AS BLOCK_PREV_SQL
FROM V$SESSION a JOIN V$SESSION b ON a.BLOCKING_SESSION = b.sid  WHERE a.BLOCKING_SESSION IS NOT NULL ;

|SID|STATUS|BLOCKING_SESSION|EVENT      |CURRENT_SQL                                            |PREV_SQL|BLOCK_CURRENT_SQL|BLOCK_PREV_SQL                                         |
|---|------|----------------|-----------|-------------------------------------------------------|--------|-----------------|-------------------------------------------------------|
|9  |ACTIVE|10              |RowLockWait|update lock_test set age = 'session2' where name = 'ff'|begin   |                 |update lock_test set age = 'session1' where name = 'ff'|



这里可以明显看到是 10 阻塞了 9


kill掉指定的SQL语句:
KILL SESSION 10 IMMEDIATE;



模拟二
session1:
begin;
update lock_test set age = 'session1' where name = 'ff';

session2:
alter table lock_test add column name1 varchar(100);


依然可以使用如上的方式查找及kill

问题总结

oscar数据库的锁排查方法

你可能感兴趣的:(SQL优化,sql)