Oracle尋找並殺掉鎖表及對象的session及相關係統進程

來源:互聯網
上載者:User

一、處理過程

    1.通過尋找出已被鎖定的資料庫表及相關的sid、serial#及spid:

     select object_name as 對象名稱,s.sid,s.serial#,p.spid as 系統進程號
     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.從系統中滅掉與該session對應的進程:

    kill -9 spid;

    --spid為第一步中查出來的系統進程號

    經過以上操作之後重新對之前鎖定的對象進行操作應該就可以了。

二、使用了相關表的基本介紹

V$LOCKED_OBJECT中的列說明:
XIDUSN:復原段號
XIDSLOT:槽號
XIDSQN:序號
OBJECT_ID:被鎖對象ID
SESSION_ID:持有鎖的sessionID
Oracle_USERNAME:持有鎖的Oracle 使用者名稱
OS_USER_NAME:持有鎖的作業系統 使用者名稱
PROCESS:作業系統進程號
LOCKED_MODE:鎖模式
dba_objects的列說明(網上找的,懶得翻譯了^_^)
OWNER
      Username of the owner of the object
   OBJECT_NAME
      Name of the object
   SUBOBJECT_NAME
      Name of the sub-object (for example,partititon)
   OBJECT_ID
      Object number of the object
   DATA_OBJECT_ID
      Object number of the segment which contains the object
   OBJECT_TYPE
      Type of the object
   CREATED
      Timestamp for the creation of the object
   LAST_DDL_TIME
      Timestamp for the last DDL change (including GRANT and REVOKE) to the object
   TIMESTAMP
      Timestamp for the specification of the object
   STATUS
      Status of the object
   TEMPORARY
      Can the current session only see data that it place in this object itself?
   GENERATED
      Was the name of this object system generated?
   SECONDARY
      Is this a secondary object created as part of icreate for domain indexes?
v$session的說明
V$SESSION是基礎資訊視圖,用於找尋使用者SID或SADDR
常用列:
SID:SESSION標識
SERIAL#:如果某個SID又被其它的session使用的話則此數值自增加(當一個SESSION結束,另一個SESSION開始並使用了同一個SID)。
AUDSID:審查session ID唯一性,確認它通常也用於當尋找並行查詢模式
USERNAME:當前session在oracle中的使用者名稱。
STATUS:這列用來判斷session狀態是:
   Achtive:正執行SQL語句(waiting for/using a resource)
   Inactive:等待操作(即等待需要執行的SQL語句)
   Killed:被標註為刪除
v$process視圖
v$process視圖包含當前系統Oracle啟動並執行所有進程資訊。常被用於將Oracle或服務進程的作業系統進程ID與資料庫session之間建立聯絡。
常用列:
ADDR:進程對象地址
PID:oracle進程ID
SPID:作業系統進程ID

相關文章

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.