Как отключить конкретную сессию в Oracle

Обновлено 07.04.2016

oracle

oracle

Всем привет, в данном посте хочу рассказать как отключить конкретную сессию в Oracle.

1) Выполнить запрос SELECT и посмотреть текущие сессии.

select t.SID, t.SERIAL#, t.osuser as "User", t.MACHINE as "PC", t.PROGRAM as "Program"
from v$session t
--where (NLS_LOWER(t.PROGRAM) = 'cashreg.exe') -- посмотреть сессии от программы cashreg.exe
--where status='ACTIVE' and osuser!='SYSTEM' -- посмотреть пользовательские сессии
--where username = 'схема' -- посмотреть сессии к схеме (пользователь)
order by 4 asc;

2) Заменить 'SID,Serial#' на 'SID,Serial#' полученных из запроса SELECT

ALTER SYSTEM KILL SESSION 'SID,Serial#' IMMEDIATE;

Как убить все сессии к схеме Oracle

/* 
This script terminates all connections to the user schema. Username must be specified in the script before execution.
The sessions may exist in the "KILLED" state while the transactions roll back

*/

define USERNAME = SCOTT

begin 
for i in (select SID, SERIAL# from V$SESSION where USERNAME = upper('&&USERNAME')) loop 
execute immediate 'alter system kill session '''||i.SID||','||i.SERIAL#||''' immediate';
end loop;
end;
/

Автор - Сёмин Иван

Добавить комментарий

Ваш адрес email не будет опубликован. Обязательные поля помечены *