如何查看和终止对ORACLE模式进行的会话列表?

时间:2014-04-05 18:02:27

标签: oracle oracle11g

我正在尝试诊断问题,并且需要查看与特定Oracle架构建立的连接列表。

假设我有DBA权限,我应该运行的查询是什么:

  1. 列出Oracle架构的会话(活动和其他),
  2. 杀死这些会议
  3. 谢谢!

1 个答案:

答案 0 :(得分:2)

以下是您需要执行的查询:

-- 1. Check connected sessions
select     sid, serial#, username, machine,
    to_char(logon_time+5/24,'ddMon hh24:mi') login,
    SQL_HASH_VALUE, PREV_HASH_VALUE,
    status
from  v$session
where
lower(username) like  '%SCHEMA_NAME%'
--and lower(status) not like '%killed%'
--and machine like '%SOURCE_MACHINE_NAME%'
order      by logon_time;

-- 2. Same as above, but just show the count of sessions  
select    count(1)
from      v$session
where      lower(username) like  lower('%SCHEMA_NAME%')
--and lower(status) not like '%inactive%'
order      by logon_time;


-- 3. Kill connected sessions
ALTER SYSTEM ENABLE RESTRICTED SESSION;
begin
    for x in (
            select Sid, Serial#, machine, program
            from v$session
            where      lower(username) like  '%SCHEMA_NAME%'
        ) loop
        execute immediate 'Alter System Kill Session '''|| x.Sid
                     || ',' || x.Serial# || ''' IMMEDIATE';
    end loop;
end;
ALTER SYSTEM DISABLE RESTRICTED SESSION;
-- May have to wait for a bit for the killed sessions to be cleaned up

我一直在Oracle 11g数据库上使用上述内容,所以希望它们也适合你。

请注意,我在前两个查询中添加了一些注释掉的子句,以便您优化搜索条件。

希望这就是你要找的东西。