Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I kill all sessions connecting to my oracle database?

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.

How would I script this?

like image 873
BIBD Avatar asked Sep 10 '08 21:09

BIBD


People also ask

Is it safe to kill INACTIVE sessions in Oracle?

2) Is it safe to kill those inactive sessions without clients approval because as their status says they are 'INACTIVE'? Safe yes - from a database instance perspective. Oracle is very robust. It does not choke when a user session suddenly disappear.


2 Answers

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; 

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

like image 189
BIBD Avatar answered Oct 14 '22 14:10

BIBD


As SYS:

startup force; 

Brutal, yet elegant.

like image 31
Gaius Avatar answered Oct 14 '22 14:10

Gaius