Oracle: (1)数据库内操作
1 2 3 4 5 6 7 |
--单实例: select 'alter system kill session '''||s.sid||','||s.SERIAL#||''' immediate;' from v$session s where s.status='INACTIVE' --状态为非活跃 and s.USERNAME= 'ZZZ' --用户为ZZZZ s.type<>'BACKGROUND' --不为oracle后台进程 and program not like '%(J0%' --不为oracle的JOB进程 order by s.LOGON_TIME asc,sql_exec_start asc; |
(2)操作系统中操作(要求登录到数据库主机)
1 2 |
## kill掉所有local=no的非本地连接进程 ps -ef|grep -v grep|grep LOCAL=NO|awk '{print $2}'|xargs kill -9 |
SQL Server:
1 2 3 |
--kill 被阻塞会话 select 'kill '+cast(spid as varchar) FROM sys.sysprocesses sp where sp.blocked !=0 and sp.spid != sp.blocked and loginame='XXX'; |