查詢鎖表:SELECT l.session_id sid,
為榆陽等地區(qū)用戶提供了全套網(wǎng)頁設計制作服務,及榆陽網(wǎng)站建設行業(yè)解決方案。主營業(yè)務為成都網(wǎng)站建設、網(wǎng)站設計、榆陽網(wǎng)站設計,以傳統(tǒng)方式定制建設網(wǎng)站,并提供域名空間備案等一條龍服務,秉承以專業(yè)、用心的態(tài)度為用戶提供真誠的服務。我們深信只要達到每一位用戶的要求,就會得到認可,從而選擇與我們長期合作。這樣,我們也可以走得更遠!
? 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 計算機名 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時候,會產生鎖表,如下驗證步驟,
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
1. 先通過top命令查看產用資源較多的spid號
2.查詢當前耗時的會話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查出當前正在使用的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.下面的語句用來殺死一個進程:
alter system kill session '524,1095'; (其中24,111分別是上面查詢出的sid,serial#)
3.再一次查詢目前鎖定的對象,若發(fā)現(xiàn)以上方法不能解除鎖定的表,則用以下方法:
3.1 執(zhí)行下面的語句獲得進程(線程)號:
select spid, osuser, s.program
from v$session s,v$process p
where s.paddr=p.addr and s.sid=524 (524是上面的sid)
鎖表:LOCK TABLE tablename IN 鎖模式 MODE;
解鎖:commit或rollback;
鎖模式有以下幾種:
ROW SHARE
ROW SHARE permits concurrent access to the locked table but prohibits users from locking the entire table for exclusive access. ROW SHARE is synonymous with SHARE UPDATE, which is included for compatibility with earlier versions of Oracle Database.
ROW EXCLUSIVE
ROW EXCLUSIVE is the same as ROW SHARE, but it also prohibits locking in SHARE mode. ROW EXCLUSIVE locks are automatically obtained when updating, inserting, or deleting.
SHARE UPDATE
See ROW SHARE.
SHARE
SHARE permits concurrent queries but prohibits updates to the locked table.
SHARE ROW EXCLUSIVE
SHARE ROW EXCLUSIVE is used to look at a whole table and to allow others to look at rows in the table but to prohibit others from locking the table in SHARE mode or from updating rows.
EXCLUSIVE
EXCLUSIVE permits queries on the locked table but prohibits any other activity on it.