oracle 会话状态,oracle 常用状态sql

--当前数据库运行状况:

select * from gv$lock

where

(type,id1,id2) in (select type,id1,id2 from gv$lock where request>0)

order by ctime desc,id1,id2,block desc;

select * from gv$locked_object ORDER BY object_id,inst_id,session_id;

select inst_id,event,wait_class,count(*) from gv$session group by inst_id,event,wait_class order by 1,4 desc;

--select * from v$session where type <> 'BACKGROUND' and status = 'ACTIVE';

SELECT * FROM v$log order by thread#,sequence#;

SELECT * FROM gv$resource_limit order by inst_id;

--统计数据库当前前台会话的操作类型及数量

select s.inst_id,s.command,a.name,s.num from (select inst_id,command,count(*) num from gv$session where  type <> 'BACKGROUND' group by inst_id,command) s,(select action,name from audit_actions) a  where a.action=s.command order by inst_id,num desc;

select t.inst_id,s.sid,s.username,s.osuser,t.START_TIME,d.timenow from gv$transaction t,gv$session s,(select to_char(sysdate,'MM/DD/YY HH24:MI:SS') timenow from dual) d where s.inst_id=t.inst_id and s.taddr= t.addr order by t.START_TIME;

--除后台会话以外的所有会话信息

SELECT inst_id,SID,event,wait_class,username,type,status,osuser,SECONDS_IN_WAIT FROM gv$session where type <> 'BACKGROUND' order by status,event,seconds_in_wait desc;

--除后台会话以外的所有正在活动的会话信息

select inst_id,SID,event,wait_class,username,type,status,osuser,SECONDS_IN_WAIT from gv$session where type <> 'BACKGROUND' and status = 'ACTIVE' order by status,event,seconds_in_wait desc;

--查某些特定等待事件的会话信息

select inst_id,SID,event,wait_class,username,type,status,osuser,SECONDS_IN_WAIT from gv$session where event like '%dblink%' or event like '%db file%read%' or event like '%SQL*Net break/reset to client%' or event like '%read by other session%' order by status,event,seconds_in_wait desc;

--查某些特定会话号的会话信息

SELECT inst_id,SID,event,wait_class,username,type,osuser,status,SECONDS_IN_WAIT FROM gv$session WHERE SID IN (126,87) order by status,event,seconds_in_wait desc;

--查询正在执行的sql

select a.SID, a.USERNAME, s.SQL_TEXT

from gv$session a, gv$sqltext_with_newlines s

where a.INST_ID=s.INST_ID

and a.SQL_ADDRESS = s.ADDRESS

and a.SQL_HASH_VALUE = s.HASH_VALUE

and a.INST_ID=1

and a.SID in (126,87)

order by a.USERNAME, a.SID, s.PIECE;

--查询上一条执行过的sql

select a.SID, a.USERNAME, s.SQL_TEXT

from gv$session a, gv$sqltext_with_newlines s

where a.INST_ID=s.INST_ID

and a.PREV_SQL_ID = s.SQL_ID

and a.INST_ID=1

and a.SID in (126,87)

order by a.USERNAME, a.SID, s.PIECE;

----++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

--查询引起cursor等待事件的会话sid

SELECT a.*, s.sql_text

FROM v$sql s,

(SELECT sid,

event,

wait_class,

p1 cursor_hash_value,

p2raw Mutex_value,

TO_NUMBER (SUBSTR (p2raw, 1, 8), 'xxxxxxxx') hold_mutex_x_sid

FROM v$session_wait

WHERE event LIKE 'cursor%') a

WHERE s.HASH_VALUE = a.cursor_hash_value;

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值