Skip to content

www.rolfje.com

Killing oracle sessions, the easy (JDBC) way.

Posted on 2006-02-23 By rolfje 2 Comments on Killing oracle sessions, the easy (JDBC) way.
Does Oracle complain about not being able to drop a table for a currently connected user, but you are sure you disconnected? Do the sessions “hang” in “inactive” state? Just log on as system, and execute the following query: 

SELECT
'ALTER SYSTEM KILL SESSION ''' || sid || ',' || serial# || '''; --',
       s.sid,
       s.serial#,
       s.osuser,
       s.username,
       s.program,
	status
FROM   v$session s
WHERE status = 'INACTIVE';

You will get a list of statements you need to execute (just copy-pase) to kill the inactive sessions. Don’t listen to the guys telling you to do intricate System Administrator stuff on a command prompt, just use any JDBC tool.

EDIT: Single query which also lists the kill command if the “alter system kill session” trick did not work:

SELECT
'ALTER SYSTEM KILL SESSION ''' || s.sid || ',' || s.serial# ||
       '''; -- kill -9 ' || p.spid,
       s.sid,
       s.serial#,
       p.spid,
       s.username,
       s.program,
       s.status
FROM   v$session s, v$process p
WHERE s.paddr = p.addr
  and (s.state='INACTIVE' or s.state='KILLED');

Thanks Bas en Jeroen!

Software Tags:Java, oracle, programming

Post navigation

Previous Post: Rotten Rotor
Next Post: You Can’t Fix What You Don’t Measure

Comments (2) on “Killing oracle sessions, the easy (JDBC) way.”

  1. rolfje says:
    2008-02-17 at 00:29

    Original comment by Jeroen:

    Leuk in combinatie hiermee: client identifier

    CREATE OR REPLACE TRIGGER LOGON_TRIGGER
    AFTER LOGON ON DATABASE
    DECLARE
    v_user_identifier varchar2(64);
    BEGIN
    SELECT SYS_CONTEXT(‘USERENV’, ‘OS_USER’)
    ||’:’||
    SYS_CONTEXT(‘USERENV’, ‘IP_ADDRESS’)
    INTO v_user_identifier
    FROM dual;
    DBMS_SESSION.SET_IDENTIFIER(v_user_identifier);
    END;

    daarna s.client_identifier toevoegen en hopla

    Reply
  2. rolfje says:
    2008-02-17 at 00:29

    Original comment by Bas:

    The above won’t work if the session has status=killed. In that case retrieve the system process id with:

    select s.username,s.osuser,s.sid,s.serial#,p.spid
    from v$session s,v$process p
    where s.paddr = p.addr
    and s.username is not null;

    and use kill -9 on unix to kill the session.

    Reply

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

           

Recent Comments

  • rolfje on Methode Buijs uitgelegd
  • LinkedIn is at Peak Enshittifaction – Will Chatham's Blog on Linked-In not really Opt-in?
  • Hans j on 1N4148 diode as RF switch
  • Roaming Rhonda on DLNA on OSX, done right
  • Frans on How to fix a Krups XN2001 Nespresso machine

Tags

Anonimatron Apple backup design DIY DRM eclipse environment Fun gmail google hacking hamradio Hardware helicopter iphone ipod iTunes Java Keynote maven modelling motorcycle music news opinion oracle osx photo photography programming repair review security Software Steve Jobs T-Mobile technology Time Machine Ubuntu usability Utilities vacation windows Workshop

Categories

  • Apple (105)
  • Divorce (1)
  • Electronics (3)
  • Fun (57)
  • Games (7)
  • Hardware (72)
  • Microsoft (18)
  • Racing (14)
  • Software (134)
  • Uncategorized (65)
  • Workshop (20)

Archives

Copyright © 2025 www.rolfje.com.

Powered by PressBook WordPress theme