Oracle 锁排查SQL

08/04 07:44
阅读数 33

查询锁SQL或ASH报告
select sql_text from v$sql where hash_value in
(select sql_hash_value from v$session where sid in
(select session_id from v$locked_object));


查询TX锁
set linesize 200 pagesize 1000
select a.inst_id,
a.sid,
a.type,
a.lmode,
a.request,
a.id1,
a.id2,
a.block,
decode(a.request, 0, 'Holder', 'Waiter') description
from gv$lock a, (select id1, id2 from gv$lock b where block = 1) b
where a.id1 = b.id1
and a.id2 = b.id2
order by a.id1,a.id2,description;













批量kill
SELECT 'alter system kill session ''' || sid || ',' || serial# || ''';' "Deadlock",username,lockwait,status,machine,program
FROM v$session where sid in
(select session_id from v$locked_object);


查看SQL执行计划是否改变,SQL执行次数
select count(*),SQL_PLAN_HASH_VALUE,sql_id
from dba_hist_active_sess_history
where sql_id in ('1vhxha315savk','978nv94bdf2uh','f8cbdrm740qhq')
and sample_time>to_timestamp('2020-07-17 00:00:00','yyyy-mm-dd hh24:mi:ss')
and sample_time<to_timestamp('2020-07-17 15:00:00','yyyy-mm-dd hh24:mi:ss')
group by SQL_PLAN_HASH_VALUE,sql_id
order by 3;






根据SQLID查询某时间段内造成的等待事件
SELECT c.username,
a.machine,
a.program,
a.sql_id,
a.sample_time,
a.event
FROM dba_hist_active_sess_history a
JOIN dba_users c
ON a.user_id = c.user_id
WHERE a.sql_id in ('1vhxha315savk') and a.sample_time BETWEEN to_date('2020-07-17 10:00:00','yyyy-mm-dd hh24:mi:ss') AND to_date('2020-07-17 11:00:00','yyyy-mm-dd hh24:mi:ss')
ORDER BY a.sample_time;










根据SQLID查看执行计划
declare
sql_task varchar2(30);
begin
sql_task := DBMS_SQLTUNE.CREATE_TUNING_TASK( sql_id => 'f8cbdrm740qhq',
scope => 'COMPREHENSIVE',
time_limit => 600,
task_name => 'sql_t1',
description => 'tunning');
DBMS_SQLTUNE.EXECUTE_TUNING_TASK(task_name => 'sql_t1');
end;
/










set long 999999;
set serveroutput on size 999999
set linesize 600;
col a for a600
set pages 1000;
select DBMS_SQLTUNE.REPORT_TUNING_TASK('sql_t1') as a from dual;




另一种方式
set autotrace traceonly explain;
alter session set current_schema=SFLCGOOD;
UPDATE FIL_PROJECT_HEAD F SET F.UPDATE_TIME=SYSDATE
, F.STATUS= 2222222222222222222222222222
WHERE F.ID=2222222222222222222222222222




查看某表索引信息
select OWNER , TABLE_NAME, INDEX_NAME , INDEX_TYPE , UNIQUENESS , STATUS from dba_indexes where TABLE_NAME = 'FI_R_BEGINNING’;

展开阅读全文
打赏
0
0 收藏
分享
加载中
更多评论
打赏
0 评论
0 收藏
0
分享
在线直播报名
返回顶部
顶部