如何杀死所有连接到oracle数据库的会话? [英] How can I kill all sessions connecting to my oracle database?

查看:714
本文介绍了如何杀死所有连接到oracle数据库的会话?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要在没有管理员的监督下迅速(强制)终止所有连接到oracle数据库的外部会话.

I need to quickly (and forcibly) kill off all external sessions connecting to my oracle database without the supervision of and administrator.

我不想只锁定数据库并让用户正常退出.

I don't want to just lock the database and let the users quit gracefully.

我该如何编写脚本?

推荐答案

此答案受此处对话的影响很大:

This answer is heavily influenced by a conversation here: http://www.tek-tips.com/viewthread.cfm?qid=1395151&page=3

ALTER SYSTEM ENABLE RESTRICTED SESSION;

begin     
    for x in (  
            select Sid, Serial#, machine, program  
            from v$session  
            where  
                machine <> 'MyDatabaseServerName'  
        ) loop  
        execute immediate 'Alter System Kill Session '''|| x.Sid  
                     || ',' || x.Serial# || ''' IMMEDIATE';  
    end loop;  
end;

我跳过杀死源自数据库服务器的会话,以避免杀死Oracle与其自身的连接.

I skip killing sessions originating on the database server to avoid killing off Oracle's connections to itself.

这篇关于如何杀死所有连接到oracle数据库的会话?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆