Oracle中查看一個表是否被鎖住

本文轉載自:https://blog.csdn.net/lizhongstu/article/details/8782809

SELECT OBJECT_NAME,SESSION_ID SID,MACHINE,VS.MODULE, 'ALTER SYSTEM KILL SESSION '''||SESSION_ID|| ', '||SERIAL#|| '''; ' KILL_SESSION,VS.STATUS,VS.ACTION,SERIAL#,ORACLE_USERNAME,OS_USER_NAME

FROM V$LOCKED_OBJECT VO, V$SESSION VS, ALL_OBJECTS AO 
WHERE VO.SESSION_ID = VS.SID AND AO.OBJECT_ID = VO.OBJECT_ID AND NVL(VS.ACTION, ' ') <> 'Service Management ' ORDER BY OBJECT_NAME,MACHINE,VS.MODULE;

 

 

 

這段代碼 可以找到,非系統鎖的表,並給出 KILL SESSION語句。可以查到是那臺機器,有什麼程序鎖的表

 

 

 

--查出所有被鎖住的表
select b.owner TABLEOWNER, b.object_name TABLENAME, c.OSUSER LOCKBY,

c.USERNAME LOGINID, c.sid SID, c.SERIAL# SERIAL
from v$locked_object a,dba_objects b, v$session c 
where b.object_id = a.object_id AND a.SESSION_ID =c.sid;
--通過SID, SERIAL解鎖 
--alter system kill session 'SID, SERIAL';

 

 

 


oracle ORA-14452錯誤處理  臨時表被鎖
create global temporary table on commit preserve rows 用於會話相關,
也就在事務結束後truncate data in the temporary table,但如果在會話未結束時要

修改temporary table就會出現錯誤:
ORA-14452: attempt to create, alter or drop an index on temporary table

already in use
經查,該錯誤的解釋爲:
Cause: An attempt was made to create, alter or drop an index on temporary

table which is already in use.
Action: All the sessions using the session-specific temporary table have to

truncate table and all the transactions using transaction specific

temporary table have to end their transactions.


處理步驟:
1、先從user_objects中查詢到該表的object_id:
select object_id from user_objects where object_name=upper

('TMP_365100930');


2、根據查到的object_id知道使用該表的session:
select * from v$lock where id1=&object_id;


3、在從v$session視圖中查到該session的SID和SERIAL#:
select * from v$session where sid=181;


4、殺掉這些進程:
alter system kill session SID,SERIAL#;


發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章