Oracle中查看一個表是否被鎖住以及Oracle ORA-14452錯誤處理

遇到的場景

在登錄時,一直提示請稍微,也沒有報用戶名或密碼錯誤,後臺可以登上Oracle 數據庫,前臺其他人也登不上,猜測是用戶表被鎖住,去查看。

查看一個表是否被鎖住

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

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;

–查出所有被鎖住的表

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、在從視圖中查到該session的SID和SERIAL#:
select * from v$session where sid=181;

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

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