事务查看
查看当前oracle未提交的事务
SELECT s.sid, s.serial#, s.event, a.sql_text, a.sql_fulltext, s.username, s.status, s.machine, s.terminal, s.program, a.executions, s.sql_id, p.spid, a.direct_writes FROM (SELECT * FROM v$session WHERE status = ‘ACTIVE‘) s LEFT JOIN v$sqlarea a ON s.sql_id = a.sql_id INNER JOIN v$process p ON s.paddr = p.addr;
查看正在执行sql的发起者的发放程序:
SELECT OSUSER 电脑登录身份, PROGRAM 发起请求的程序, USERNAME 登录系统的用户名, SCHEMANAME, B.Cpu_Time 花费cpu的时间, STATUS, B.SQL_TEXT 执行的sql FROM V$SESSION A LEFT JOIN V$SQL B ON A.SQL_ADDRESS = B.ADDRESS AND A.SQL_HASH_VALUE = B.HASH_VALUE ORDER BY b.cpu_time DESC
查询Oracle正在执行的sql语句及执行该语句的用户
SELECT b.sid oracleID, b.username 登录Oracle用户名, b.serial#, spid 操作系统ID, paddr, sql_text 正在执行的SQL, b.machine 计算机名 FROM v$process a, v$session b, v$sqlarea c WHERE a.addr = b.paddr AND b.sql_hash_value = c.hash_value;
表锁
查询锁表的session
select b.username,b.sid,b.serial# serial,c.object_name,a.locked_mode,d.sql_text
,d.first_load_time,d.last_load_time
from v$locked_object a
left join v$session b on a.session_id = b.sid
left join dba_objects c on c.object_id = a.object_id
left join v$sql d on b.sql_hash_value = d.hash_value
order by b.logon_time;
删除session
alter system kill session‘sid,serial#‘;
如果session删除不掉,报错,就需要我们在OS上杀死这个进程(线程)
1、查出spid
select spid, osuser, s.program from v$session s,v$process p where s.paddr=p.addr and s.sid=33 (33就是上面的sid)
2、unix上,用root身份执行命令
kill -9 spid
windows(unix)
orakill 【实例名】 【spid】 例如 orakill orcl 12345