본문 바로가기
IT

[Oracle] Session Kill 방법

by 쪼이빠빠 2023. 2. 28.
728x90
반응형
### LOCAL=NO 세션 강제 종료 절차 (전체)


1) 백그라운드 프로세스 이외, 단순 서비스 접속 세션(LOCAL=NO) 조회

(SID 에 따른 oracle 프로세스 변경 사용 필수!)
aaa=`ps -ef|grep LOCAL=NO|grep oracle[SID]|grep -v grep|awk '{print $2}'`


2) kill 대상 세션 조회

echo $aaa

 

3) 세션 kill

kill -9 $aaa

### 불필요한 일부 세션 강제 종료 절차


1) 아래의 SQL 활용하여, 조건 수정해서 대상 선별

2) 결과값으로 서버에서 세션 kill 실행

(Sample SQL)

select distinct s.inst_id "ID", s.status "Status",p.spid, s.SID, s.serial#,
       s.sql_id "Sql id", round(s.last_call_et) "els(Sec)", event,
       s.username "DB User", s.osuser "Client User", s.machine "Machine", s.module "Module",
       s.terminal "Terminal", s.program "Program", p.program "O.S. Program", lockwait "Lock Wait",
       s.blocking_session_status "block ses stat", s.blocking_instance "block instance", s.blocking_session "block session",
       s.logon_time "Connect Time",sysdate - (s.last_call_et / 86400) "Last Call"
from   gv$session s, gv$process p
where  s.paddr = p.addr(+) and s.inst_id = p.inst_id(+)
and    s.type <> 'BACKGROUND'
and    s.status = 'ACTIVE'
--and    p.spid in (12133, 12100)
--and    s.SID in (1749)
--and    s.sql_id = ''
--and    s.username = ''
--and    s.osuser not in ('DBSNMP','SYSMAN')
--and    s.blocking_session is not null
--and    s.machine = ''
--and    s.module like 'JDBC Thin Client%'
order  by s.inst_id, "els(Sec)" desc
;

(kill SQL)

select 'kill -9 '||p.spid
from   gv$session s, gv$process p
where  s.paddr = p.addr(+) and s.inst_id = p.inst_id(+)
and    s.type <> 'BACKGROUND'
and    s.status = 'ACTIVE'
--and    p.spid in (12133, 12100)
--and    s.SID in (1749)
--and    s.sql_id = 'ck17jd0fufztx'
--and    s.username = ''
--and    s.osuser not in ('','')
--and    s.blocking_session is not null
--and    s.machine = ''
--and    s.module like 'JDBC Thin Client%'
;

반응형

댓글