1、数据库出现hang处置过程:
sql
sqlplus -prelim / as sysdba
oradebug setmypid
oradebug unlimit
oradebug hanganalyze 3
oradebug dump systemstate 266
oradebug tracefile_name -- 此命令生成dump文件,根据命令提示的路径查看dump文件
oradebug close_trace;
2、数据库连不上时,可以使用以下命令杀会话:
bash
ps -ef | grep SID | grep LOCAL=NO | awk '{print $2}' | xargs kill -9
3、如果数据库可以连接,可以使用SQL杀会话:
sql
select a.inst_id,
a.username,
a.logon_time,
a.status,
'alter system kill session ''' || a.sid || ',' || a.serial# || ''',',
'kill -9 ' || b.spid
from gv$session a,
gv$process b,
dba_users u
where a.inst_id = 1
and a.paddr = b.addr
and a.status = 'INACTIVE'
and a.username not in ('SYS', 'SYSTEM')
and a.username = u.username
and u.default_tablespace not in ('SYSTEM', 'SYSAUX')
and a.type = 'USER'
and to_char(a.logon_time, 'yyyy-mm-dd hh24:mi:ss') < to_char(sysdate - 2 / 24, 'yyyy-mm-dd hh24:mi:ss')
group by a.inst_id,
a.username,
a.logon_time,
a.status,
a.sid,
a.serial#,
b.spid,
a.type
order by username, logon_time desc;