1. 先通過(guò)top命令查看產(chǎn)用資源較多的spid號(hào)
烏海ssl適用于網(wǎng)站、小程序/APP、API接口等需要進(jìn)行數(shù)據(jù)傳輸應(yīng)用場(chǎng)景,ssl證書(shū)未來(lái)市場(chǎng)廣闊!成為創(chuàng)新互聯(lián)的ssl證書(shū)銷售渠道,可以享受市場(chǎng)價(jià)格4-6折優(yōu)惠!如果有意向歡迎電話聯(lián)系或者加微信:18980820575(備注:SSL證書(shū)合作)期待與您的合作!
2.查詢當(dāng)前耗時(shí)的會(huì)話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.查詢哪些對(duì)象被鎖:
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.下面的語(yǔ)句用來(lái)殺死一個(gè)進(jìn)程:
alter system kill session '524,1095'; (其中24,111分別是上面查詢出的sid,serial#)
3.再一次查詢目前鎖定的對(duì)象,若發(fā)現(xiàn)以上方法不能解除鎖定的表,則用以下方法:
3.1 執(zhí)行下面的語(yǔ)句獲得進(jìn)程(線程)號(hào):
select spid, osuser, s.program
from v$session s,v$process p
where s.paddr=p.addr and s.sid=524 (524是上面的sid)
查詢鎖表
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;
解表
ALTER system kill session 'sid, serial#';
ALTER system kill session '256, 34034';
首先你要知道表鎖住了是不是正常鎖?因?yàn)槿魏蜠ML語(yǔ)句都會(huì)對(duì)表加鎖。\x0d\x0a\x0d\x0a你要先查一下是那個(gè)會(huì)話那個(gè)sql鎖住了表,有可能這是正常業(yè)務(wù)需求,不建議隨便KILLsession,如果這個(gè)鎖表是正常業(yè)務(wù)你把sessionkill掉了會(huì)影響業(yè)務(wù)的。\x0d\x0a建議先查原因再做決定。\x0d\x0a\x0d\x0a(1)鎖表查詢的代碼有以下的形式:\x0d\x0aselectcount(*)fromv$locked_object;\x0d\x0aselect*fromv$locked_object;\x0d\x0a(2)查看哪個(gè)表被鎖\x0d\x0aselectb.owner,b.object_name,a.session_id,a.locked_modefromv$locked_objecta,dba_objectsbwhereb.object_id=a.object_id;\x0d\x0a(3)查看是哪個(gè)session引起的\x0d\x0aselectb.username,b.sid,b.serial#,logon_timefromv$locked_objecta,v$sessionbwherea.session_id=b.sidorderbyb.logon_time;\x0d\x0a\x0d\x0a(4)查看是哪個(gè)sql引起的\x0d\x0aselectb.username,b.sid,b.serial#,c.*fromv$locked_objecta,v$sessionb,v$sqlcwherea.session_id=b.sid\x0d\x0aandb.SQL_ID=c.sql_idandc.sql_id=''\x0d\x0aorderbyb.logon_time;\x0d\x0a\x0d\x0a(5)殺掉對(duì)應(yīng)進(jìn)程\x0d\x0a執(zhí)行命令:altersystemkillsession'1025,41';\x0d\x0a其中1025為sid,41為serial#.
在對(duì)指定表做append操作,其他再做truncate時(shí)候,會(huì)產(chǎn)生鎖表,如下驗(yàn)證步驟,
1、創(chuàng)建測(cè)試表,
create table test_lock(id number, value varchar2(200));
2、執(zhí)行append語(yǔ)句;并且不做提交,insert /*+append*/ into test_lock values(1,1);
3、再次執(zhí)行清表語(yǔ)句,truncate table test_lock;報(bào)鎖表錯(cuò)誤,
4、查看鎖表語(yǔ)句,發(fā)現(xiàn)被鎖表,
select b.object_name, t.*
from v$locked_object t, user_objects b
where t.object_id = b.object_id
查詢鎖表: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ì)算機(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';