成都网站建设设计

将想法与焦点和您一起共享

Oracle查看锁表情况并处理锁表-创新互联

/
locked
*query locked object and analyse reason,kill it

桓台网站制作公司哪家好,找创新互联建站!从网页设计、网站建设、微信开发、APP开发、成都响应式网站建设公司等网站项目制作,到程序开发,运营维护。创新互联建站自2013年起到现在10年的时间,我们拥有了丰富的建站经验和运维经验,来保证我们的工作的顺利进行。专注于网站建设就选创新互联建站
  • */

select 'alter system kill session ''' || SID || ',' || SERIAL# || ''';'
from (select distinct a.sid,
a.Serial#,
status,
machine,
LOCKWAIT,
logon_time
from v$session a, v$locked_object b
where (a.status = 'ACTIVE' or a.status = 'INACTIVE')
and a.sid = b.session_id
and b.ORACLE_USERNAME = 'XYHISTEST' --加上用户名可过滤用户资源
);

/2、批量执行第一步生成的语句
alter system kill session 'sid,serial#';
alter system kill session '6976,33967';
/

/3、查询oracle用户名,机器名,锁表对象/
SELECT l.session_id sid,
s.serial#,
l.locked_mode,
l.oracle_username,
l.os_user_name,
s.machine,
s.terminal,
o.object_name,
s.logon_time
FROM v$locked_object l, all_objects o, v$session s
WHERE l.object_id = o.object_id
AND l.session_id = s.sid
ORDER BY sid, s.serial#;

/3.或者/
select s.SID, s.OSUSER, p.spid as OSPID, s.MACHINE, s.TERMINAL, s.PROGRAM
from v$session s, v$process p
where s.sid = 6 --session_id
and s.paddr = p.addr;

/4、查询是执行何sql语句导致锁表的/
select b.sql_text
from v$session a, v$sql b
where a.sid = 6 --session_id
and a.SQL_ADDRESS = b.ADDRESS(+);

select sql_text
from v$session a, v$sqltext_with_newlines b
where DECODE(a.sql_hash_value, 0, prev_hash_value, sql_hash_value) =
b.hash_value
and a.sid = #149
order by piece;

/5、查询是执行何sql语句导致锁表的/
SELECT l.session_id sid,
s.serial#,
l.locked_mode,
l.oracle_username,
s.user#,
l.os_user_name,
s.machine,
s.terminal,
a.sql_text,
a.action
FROM v$sqlarea a, v$session s, v$locked_object l
WHERE l.session_id = s.sid
AND s.prev_sql_addr = a.address
ORDER BY sid, s.serial#;

/6、查看是否有锁表的 SQL/
select 'blocker(' || lb.sid || ':' || sb.username || ')_sql:' ||
qb.sql_text blockers,
'waiter (' || lw.sid || ':' || sw.username || ')_sql:' ||
qw.sql_text waiters
from v$lock lb, v$lock lw, v$session sb, v$session sw, v$sql qb, v$sql qw
where lb.sid = sb.sid
and lw.sid = sw.sid
and sb.prev_sql_addr = qb.address
and sw.sql_address = qw.address
and lb.id1 = lw.id1
and sw.lockwait is not null
and sb.lockwait is null
and lb.block = 1;

另外有需要云服务器可以了解下创新互联scvps.cn,海内外云服务器15元起步,三天无理由+7*72小时售后在线,公司持有idc许可证,提供“云服务器、裸金属服务器、高防服务器、香港服务器、美国服务器、虚拟主机、免备案服务器”等云主机租用服务以及企业上云的综合解决方案,具有“安全稳定、简单易用、服务可用性高、性价比高”等特点与优势,专为企业上云打造定制,能够满足用户丰富、多元化的应用场景需求。


本文题目:Oracle查看锁表情况并处理锁表-创新互联
本文URL:http://chengdu.cdxwcx.cn/article/despds.html