Skip to content

Instantly share code, notes, and snippets.

@aimtiaz11
Last active August 29, 2015 14:03
Show Gist options
  • Save aimtiaz11/9e4f2f81f6a021f5dc07 to your computer and use it in GitHub Desktop.
Save aimtiaz11/9e4f2f81f6a021f5dc07 to your computer and use it in GitHub Desktop.
Kill Database Session

Killing Oracle Database Session

Run the following in SQL* Plus as SYS/SYSDBA user to terminate sessions.

** Update username with your schema name.

DECLARE
	CURSOR c1 is 
	SELECT s.inst_id,
	s.sid,
	s.serial#,
	p.spid,
	s.username,
	s.program
	FROM   gv$session s
	JOIN gv$process p ON p.addr = s.paddr 
	AND p.inst_id = s.inst_id
	WHERE  s.type != 'BACKGROUND'
	and UPPER(s.username) = 'SCOTT';
BEGIN
	FOR rec in c1 LOOP
		EXECUTE IMMEDIATE 'ALTER SYSTEM KILL SESSION '''||rec.SID||','||rec.serial#||'''';
	END LOOP;
END;
/
show errors;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment