ALTER SYSTEM KILL SESSION '4033,33518'; --解除被鎖定的會話信息
在寧德等地區(qū),都構(gòu)建了全面的區(qū)域性戰(zhàn)略布局,加強(qiáng)發(fā)展的系統(tǒng)性、市場前瞻性、產(chǎn)品創(chuàng)新能力,以專注、極致的服務(wù)理念,為客戶提供成都做網(wǎng)站、成都網(wǎng)站制作 網(wǎng)站設(shè)計制作按需網(wǎng)站制作,公司網(wǎng)站建設(shè),企業(yè)網(wǎng)站建設(shè),成都品牌網(wǎng)站建設(shè),成都全網(wǎng)營銷推廣,成都外貿(mào)網(wǎng)站制作,寧德網(wǎng)站建設(shè)費(fèi)用合理。
select session_id from v$locked_object; --查看哪個會話被鎖了
SELECT sid, serial#, username, osuser FROM v$session where sid = 4033; --查看具體被鎖會話信息
在對指定表做append操作,其他再做truncate時候,會產(chǎn)生鎖表,如下驗(yà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
oracle數(shù)據(jù)庫分行級鎖和表級鎖。用select * from table-name for update完成行級鎖。用delete或update完成表級鎖。你鎖定的資源 別人會等待你的提交語句或回退語句完成以后再繼續(xù)進(jìn)行。
查詢鎖表: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';
1. 先通過top命令查看產(chǎn)用資源較多的spid號
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)