Killing Oracle sessions
See here for recent notes on
alter system kill session.
Methods of Murder by
Other than the aforementioned abort option
for the SHUTDOWN command, which after all is rather rude, what are
the methods of killing these recalcitrant sessions? Essentially, you
can issue an ALTER SYSTEM KILL SESSION or you can issue a manual
process kill command such as the UNIX: kill -9 pid from the
operating system side. You should do one or the other of these types
of kill operations, but not both. If you kill both the Oracle
process and the operating system process, it can result in database
hang situations, which will force you to perform a shutdown abort.
Killing from the Oracle Side
The DBA can either issue a series of ALTER
SYSTEM commands manually or develop a dynamic SQL script to perform
the operation. Source 2.3 shows a PL/SQL procedure to perform a kill
of a process using the dynamic SQL package of procedures: DBMS_SQL.
In Oracle8i, a new option is available for the ALTER SYSTEM that
allows disconnection of the user process after a transaction
completes. The commented-out section in Source 2.3 shows this
alternative to a straight kill.
Using the procedure from Source 2.3 the DBA
can then create a quick SQL procedure to remove the nonrequired
Oracle sessions from the Oracle side. An example of this procedure
is shown in Source 2.4. An example of the output from ora_kill.sql (kill_all.sql)
is shown in Listing 2.4.
See Code Depot
Important Oracle 11g changes to alter session kill
Oracle author Mladen Gogala notes that an @ sign is now required to
kill a session when using the inst_id column:
select inst_id,sid,serial# from gv$session where username='SCOTT';
---------- ---------- ----------
SQL> alter system kill session '130,620,1';
alter system kill session '130,620,1'
ERROR at line 1:
ORA-00026: missing or invalid session ID
Now, it works:
SQL> alter system kill session '130,620,@1';