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 *

         
Reposted by @rolfje.com
@shadowmakersdr.bsky.social
Ik ben blij dat de overheid zo consequent is in z'n campagnes. Iedereen fulltime werken, maar wel buiten de spits naar je werk en gebruik de stroom van je zonnepanelen overdag (als je niet thuis bent want op je werk) terwijl je mantelzorgt èn fsyieke winkels bezoekt om 'de winkelstraat' te redden.
2 days ago
@rolfje.com
Volgtip! "Koppen Verklapt" maakt een einde aan die verschrikkelijk irritante koppen.
20 hours ago
@rolfje.com
Een kop vertelt nooit het hele verhaal. Zie realrolfje.github.io/coronadata/i...
1 day ago

Recent Comments

  • Monica Hall on Het belastinghuiswerk nagekeken
  • rolfje on Spring SystemPropertyInitializingBean
  • plinko idle clicker on Spring SystemPropertyInitializingBean
  • rolfje on The podcast problem (fixed)
  • SirenMix on The podcast problem (fixed)

Tags

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

Categories

  • Apple (107)
  • Divorce (1)
  • Electronics (5)
  • Fun (58)
  • Games (8)
  • Hardware (74)
  • Microsoft (18)
  • Racing (16)
  • Software (144)
  • Uncategorized (69)
  • Workshop (23)

Archives

Brought to you without adds, banners, cookies or tracking. This one is on me. Yes, life can be this good. Pay it forward.
AI policy - Privacy policy

Copyright © 2026 www.rolfje.com.

Powered by PressBook WordPress theme