1.查看session可以把status改為ACTIVE和INACTIVE
v$session 和gv$session 只在RAC中區別明顯,有g是全局的,rac的兩個數據庫中的內容,沒有是但實例的數據庫的,內容不全
rac么? gv$開頭視圖是rac全局的,v$開頭是本節點的
gv$session比v$session多一個字段而已: INST_ID
select machine ,count(*) from gv$session where logon_time < sysdate -1 and status ='INACTIVE' group by machine;
2.查看目前的session已經正在執行的sql
SELECT S.USERNAME,
S.SID,
S.SERIAL#,
S.INST_ID,
S.EVENT,
S.WAIT_CLASS,
S.SQL_EXEC_START,
S.LOGON_TIME,
S.ACTION,
SQ.SQL_TEXT,
S.MACHINE
FROM GV$SESSION S, GV$SQLAREA SQ
WHERE S.STATUS = 'ACTIVE'
AND S.USERNAME IS NOT NULL
AND S.SQL_ID = SQ.SQL_ID;
3.單節點生成批量kill session的sql
select 'alter system kill session ''' || sid || ',' || serial# || ''' immediate;' cmd from v$session
where username is not null
and status = 'ACTIVE'
4.RAC架構生成批量kill session的sql
方法一、在節點一執行
select 'alter system kill session ''' || sid || ',' || serial# || ''' immediate;' cmd from v$session
where username is not null
and status = 'ACTIVE'
生成的kill語句,在節點一服務器執行
在節點二執行
select 'alter system kill session ''' || sid || ',' || serial# || ''' immediate;' cmd from v$session
where username is not null
and status = 'ACTIVE'
生成的kill語句,在節點二服務器執行
需要分別殺掉
方法二、在一個節點執行
select 'alter system kill session ''' || sid || ',' || serial# || ''' immediate;' cmd
from gv$session
where username is not null and to_char(prev_exec_start,'yyyy-mm-dd hh24:mi:ss') < '2021-10-18 10:37:00' and status = 'INACTIVE'
and inst_id=1;
inst_id=1 指定節點,節點二可以用inst_id=2
生成的kill語句,在節點二服務器執行
生成刪除指定時間點的KILL session語句
select 'alter system kill session ''' || sid || ',' || serial# || ''' immediate;' cmd
from v$session
where username is not null and to_char(prev_exec_start,'yyyy-mm-dd hh24:mi:ss') < '2021-10-5 00:00:00' and status = 'INACTIVE'
4. 查看某個時間點的active session的數量
select sample_time,count(*) from dba_hist_active_sess_history where sample_time < to_date('20211018 10:30','yyyymmdd hh24:mi') and sample_time > to_date('20211018 10:00','yyyymmdd hh24:mi')
group by sample_time order by sample_time
5. Kill session的方法