1. 先通過top命令查看產(chǎn)用資源較多的spid號
創(chuàng)新互聯(lián)是由多位在大型網(wǎng)絡(luò)公司、廣告設(shè)計公司的優(yōu)秀設(shè)計人員和策劃人員組成的一個具有豐富經(jīng)驗的團(tuán)隊,其中包括網(wǎng)站策劃、網(wǎng)頁美工、網(wǎng)站程序員、網(wǎng)頁設(shè)計師、平面廣告設(shè)計師、網(wǎng)絡(luò)營銷人員及形象策劃。承接:成都網(wǎng)站建設(shè)、網(wǎng)站設(shè)計、網(wǎng)站改版、網(wǎng)頁設(shè)計制作、網(wǎng)站建設(shè)與維護(hù)、網(wǎng)絡(luò)推廣、數(shù)據(jù)庫開發(fā),以高性價比制作企業(yè)網(wǎng)站、行業(yè)門戶平臺等全方位的服務(wù)。
2.查詢當(dāng)前耗時的會話ID,用戶名,sqlID等:
select sid,serial#,machine,username,program,sql_hash_value,sql_id,
? to_char(logon_time,'yyyy/mm/dd hh24:mi:ss') as login_time from v$session
where paddr in (select addr from v$process where spid in ('5648612','256523'));
3. 如果上一步sql_id或者 hash_value不為空,則可用v$sqlarea查出當(dāng)前正在使用的sql
select sql_text
from v$sqltext_with_newlines
where hash_value = hash_value
order by piece;
也可直接使用:
select a.*,b.SQL_TEXT from (
select sid,serial#,machine,username,program,sql_hash_value,sql_id,
? to_char(logon_time,'yyyy/mm/dd hh24:mi:ss') as login_time from v$session
where paddr in (select addr from v$process where spid in ('23226'))
) a,v$sql b
where a.sql_id? = b.SQL_ID(+)
4.kill占用大資源的session
Alter system kill session 'SID,SERIAL#'
解鎖:
1.查詢哪些對象被鎖:
select object_name,machine,s.sid,s.serial#
from v$locked_object l,dba_objects o ,v$session s
where l.object_id = o.object_id and l.session_id=s.sid;
2.下面的語句用來殺死一個進(jìn)程:
alter system kill session '524,1095'; (其中24,111分別是上面查詢出的sid,serial#)
3.再一次查詢目前鎖定的對象,若發(fā)現(xiàn)以上方法不能解除鎖定的表,則用以下方法:
3.1 執(zhí)行下面的語句獲得進(jìn)程(線程)號:
select spid, osuser, s.program
from v$session s,v$process p
where s.paddr=p.addr and s.sid=524 (524是上面的sid)
查詢鎖表:SELECT l.session_id sid,
? s.serial#,
? l.locked_mode,
? l.oracle_username,
? l.os_user_name,
? s.machine,
? s.terminal,
? o.object_name,
? s.logon_time FROM? v$locked_object l,
? all_objects? ? ? o,
? v$session? ? ? ? s WHERE l.object_id = o.object_id ANd l.session_id = s.sid ORDER BY sid,
? s.serial#;
解鎖:ALTER system KILL session 'sid,serial#';
查詢鎖住原因:SELECT b.sid oracleID,b.username 登錄Oracle用戶名,b.serial#,spid 操作系統(tǒng)ID,paddr,?
sql_text 正在執(zhí)行的SQL,b.machine 計算機(jī)名 FROM v$process a, v$session b, v$sqlarea c?
WHERE a.addr = b.paddr AND b.sql_hash_value = c.hash_value? and b.USERNAME='FKPHIS24';
在對指定表做append操作,其他再做truncate時候,會產(chǎn)生鎖表,如下驗證步驟,
1、創(chuàng)建測試表,
create table test_lock(id number, value varchar2(200));
2、執(zhí)行append語句;并且不做提交,insert /*+append*/ into test_lock values(1,1);
3、再次執(zhí)行清表語句,truncate table test_lock;報鎖表錯誤,
4、查看鎖表語句,發(fā)現(xiàn)被鎖表,
select b.object_name, t.*
from v$locked_object t, user_objects b
where t.object_id = b.object_id