Oracle鎖表了如何處理

來源:互聯網
上載者:User

[解決方案]

1)通過尋找已被鎖定的資料庫表以及相關的sid,serial#,spid;

select object_name,s.sid,s.serial#,p.spid from v$locked_object l,dba_objects o,v$session s,v$process p where l.object_id=o.object_id and l.session_id=s.sid and s.paddr=p.addr;

 

2)在資料庫中殺死Session

alter system kill session 'sid,serial#'; --sid,serial#是上面查詢出來的結果;

 

3)殺死對應的應用程式

kill -9 spid

 

執行步驟示範:

[1] % sqlplus "/as sysdba"

 

SQL*Plus: Release 11.1.0.6.0 - Production on Fri Nov 26 09:10:32 2010

 

Copyright (c) 1982, 2007, Oracle.  All rights reserved.

 

 

Connected to:

Oracle Database 11g Enterprise Edition Release 11.1.0.6.0 - 64bit Production

With the Partitioning and Real Application Testing options

 

SQL> select object_name,o.owner,s.sid,s.serial#,p.spid from v$locked_object l,dba_objects o,v$session s,v$process p where l.object_id=o.object_id and l.session_id=s.sid and s.paddr=p.addr;

 

OBJECT_NAME  OWNER  SID    SERIAL#  SPID 

-------------        -------    ----------  ----------  ------

EXTTEST         LYJ       139     221    26402

 

SQL> !ps -ef|grep 26402

  oracle 27588  5389  1 10:29:37 pts/tc    0:00 /usr/bin/csh -c ps -ef|grep 26402

  oracle 26402 26401  0 10:25:25 ?         0:00 oracleora11g (DESCRIPTION=(LOCAL=YES)(ADDRESS=(PROTOCOL=beq)))

  oracle 27590 27588  0 10:29:37 pts/tc    0:00 grep 26402

 

說明:根據上面查詢出來的sid,serial#,殺死Session;

SQL> alter system kill session '139,221';

 

System altered.

 

說明:可以看到Session殺死後,已經查詢不到鎖的對象;

SQL>  select object_name,o.owner,s.sid,s.serial#,p.spid from v$locked_object l,dba_objects o,v$session s,v$process p where l.object_id=o.object_id and l.session_id=s.sid and s.paddr=p.addr;

 

no rows selected

 

說明:可以看到Session殺死後,進程依然存在;

SQL> !ps -ef|grep 26402

  oracle 27951 27949  0 10:30:49 pts/tc    0:00 grep 26402

  oracle 27949  5389  1 10:30:49 pts/tc    0:00 /usr/bin/csh -c ps -ef|grep 26402

  oracle 26402 26401  0 10:25:25 ?         0:00 oracleora11g (DESCRIPTION=(LOCAL=YES)(ADDRESS=(PROTOCOL=beq)))

 

說明:根據進程PID殺死進程;

SQL> !kill -9 26402

 

SQL> !ps -ef|grep 26402

  oracle 28110 28108  0 10:31:25 pts/tc    0:00 grep 26402

  oracle 28108  5389  1 10:31:25 pts/tc    0:00 /usr/bin/csh -c ps -ef|grep 26402

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.