lock处理
作者:互联网
--查询锁会话
select s.sid,s.serial#,s.username,s.command,s.status,s.schemaname,s.osuser,s.module,s.machine,s.program,
s.sql_id,s.sql_exec_start,s.prev_sql_id,s.prev_exec_start,
s.row_wait_obj#,s.last_call_et,s.blocking_session_status,s.event from gv$session s
where s.event like '%lock%'; in ('enq: TM - contention','enqueue');
--阻塞者和被阻者
select a.sid holdsid, b.sid waitsid,a.type,a.id1,a.id2,a.ctime
from gv$lock a,gv$lock b
where a.id1=b.id1 and a.id2=b.id2 and a.block=1 and b.block=0;
--阻塞者
select * from gv$lock where lmode>0 and type in ('TM','TX');
--被阻塞
select * from gv$lock where lmode=0 and type in ('TM','TX');
--select * from v$locked_object;
---通过系统PID查找对应session
select p.spid,s.username,s.sid,s.serial#,s.sql_id from v$process p,v$session s where s.paddr=p.addr and p.spid=156326;
---通过sid查找会话信息
select s.sid,s.serial#,s.sql_id,s.prev_sql_id,username,s.username,s.command,s.status,s.schemaname,s.osuser,s.module,s.machine,s.program,
s.sql_exec_start,s.prev_exec_start,
s.row_wait_obj#,s.last_call_et,s.blocking_session_status,s.event from gv$session s where s.sid in ('613','342','1294');
---查询当前等待事件
select event , count(*) from v$session_wait group by event order by 2 desc ;
---通过sqlid查找语句
select * from v$sqlarea s where s.sql_id in
( 'ghvydq9hha686',
'9hapwfq6fuqgu',
'chnf9k4vq3400',
'4tpp0sh9cmrpd',
'8mgp0pa5jqnzn'
);
--查询执行计划
select * from table(dbms_xplan.display_cursor('928857gnnugua'))
---历史会话信息
select --distinct s.sql_id , count(1) cnt
s.instance_number, s.session_id,s.session_serial#,s.sql_id,s.user_id,s.program,s.module,s.machine,s.blocking_session,s.blocking_session_serial#,s.sample_time,s.event
from dba_hist_active_sess_history s
where s.sample_time between sysdate-0.8 and sysdate
and s.event='enq: TM - contention' and s.blocking_session is not null
--group by s.sql_id
order by s.sample_time desc;
select * from dba_hist_sqltext s where s.sql_id in (‘’,‘’);
select * from v$sqlarea s where s.sql_id in (‘’,‘’);
SELECT * FROM GV$SQL WHERE SQL_ID='3ndpq1p46gawx';
select * from table(dbms_xplan.display_cursor('ahudb2vgpqpx6'));
select * from dba_hist_snapshot;
SELECT * FROM DBA_TAB_COL_STATISTICS WHERE OWNER='JXOA' AND TABLE_NAME ='FLOWLOG';
select * from dba_constraints where table_name in('RATIFYLOG','FLOWLOG','FLOWCTRL') and owner ='JXOA';
select * from dba_objects o where o.object_id in (
'84110',
'84039',
'83223',
'83034',
'2228232'
);
ORACLE 查询所有表、外键、主键等信息
Select a.Owner 外键拥有者,
a.Table_Name 外键表,
c.Column_Name 外键列,
b.Owner 主键拥有者,
b.Table_Name 主键表,
d.Column_Name 主键列,
c.Constraint_Name 外键名,
d.Constraint_Name 主键名
From dba_Constraints a,
dba_Constraints b,
dba_Cons_Columns c, --外键表
dba_Cons_Columns d --主键表
Where a.r_Constraint_Name = b.Constraint_Name
And a.Constraint_Type = 'R'
And b.Constraint_Type = 'P'
And a.r_Owner = b.Owner
And a.Constraint_Name = c.Constraint_Name
And b.Constraint_Name = d.Constraint_Name
And a.Owner = c.Owner
And a.Table_Name = c.Table_Name
And b.Owner = d.Owner
And b.Table_Name = d.Table_Name
AND A.OWNER='JXOA'
And b.Table_Name in ('FLOWLOG','RATIFYLOG');
//查询表的主键约束名
select * from dba_constraints e where E.OWNER='JXOA' And e.table_name='FLOWLOG' ;—-处输入表名
//查询所有引用到该主键的记录
select b.table_name,b.column_name from user_constraints?a
inner join user_cons_columns b
on a.constraint_name = b.constraint_name
where a.r_constraint_name=''—此处输入刚才查询出来的表主键的约束名"
标签:Name,处理,lock,session,sql,where,id,select 来源: https://www.cnblogs.com/taojh1205/p/16695115.html