2017年2月14日 星期二

TABLE LOCK KILL

1.先查出要砍掉的session
select b.object_name obj_name,
       d.ctime time,
       to_char(d.lmode) l,
       to_char(d.request) r,
       a.os_user_name os_user,
       c.machine machine,
       c.program program,
       c.serial# s_serial,
       a.oracle_username ora_user,
       a.object_id obj_id,
       a.process pid,
       a.session_id s_id,
       p.spid
from v$locked_object a, all_objects b, v$session c, v$lock d,V$process p
where a.object_id=b.object_id
and c.Paddr = p.Addr
and a.session_id=c.sid
and a.session_id=d.sid
--and d.type='TX'
order by d.ctime desc, p.spid;

2.unix 砍掉該spid session
ps -ef
kill -9

1 則留言:

JC 提到...

---正在執行的
select a.username, a.sid,b.SQL_TEXT, b.SQL_FULLTEXT
from v$session a, v$sqlarea b
where a.sql_address = b.address

---執行過的
select b.SQL_TEXT,b.FIRST_LOAD_TIME,b.SQL_FULLTEXT
from v$sqlarea b
where b.FIRST_LOAD_TIME between '2009-10-15/09:24:47' and
'2009-10-15/09:24:47' order by b.FIRST_LOAD_TIME
(此方法好處可以查看某一時間段執行過的sql,並且 SQL_FULLTEXT 包含了完整的 sql 語句)

--查找前十條性能差的sql.
SELECT * FROM (select PARSING_USER_ID,EXECUTIONS,SORTS,
COMMAND_TYPE,DISK_READS,sql_text FROM v$sqlarea
order BY disk_reads DESC )where ROWNUM<10 ;

--查看占io較大的正在運行的session
SELECT se.sid,se.serial#,pr.SPID,se.username,se.status,
se.terminal,se.program,se.MODULE,、se.sql_address,st.event,st.
p1text,si.physical_reads,
si.block_changes FROM v$session se,v$session_wait st,
v$sess_io si,v$process pr WHERE st.sid=se.sid AND st.
sid=si.sid AND se.PADDR=pr.ADDR AND se.sid>6 AND st.
wait_time=0 AND st.event NOT LIKE '%SQL%' ORDER BY physical_reads DESC