oracle中session跟process的研究
首先看看v$session跟v$process中主要的欄位屬性:
v$session(sid,serial#,paddr,username,status,machine,terminal,sql_hash_value,sql_address,,,)
v$process(addr,spid,,,)
可看到v$session中的paddr跟v$process中的addr對應,也即會話session在資料庫主機上對應程式的程式地址.
這裡我們要先定位該session正在執行的sql語句,此時我們可以查詢如下的語句:
select sql_text
from v$sqltext_with_newlines
where (hash_value,address) in (select sql_hash_value,sql_address from v$session where sid=&sid) order by address,piece;
若需手工kill一個session,可採用"alter system kill session 'sid,serial#' immediate",此時session的狀態會標記為killed,該session對應程式地址指向相同的虛擬地址,見如下的查詢:
SQL> select sid,serial#,paddr,status from v$session where username='SHIYIHAI';
SID SERIAL# PADDR STATUS
---------- ---------- ---------------- --------
234 14409 C0000000B2BADB28 INACTIVE
245 14374 C0000000B2BAB748 INACTIVE
SQL> alter system kill session '234,14409' immediate;
System altered
SQL> select sid,serial#,paddr,status from v$session where username='SHIYIHAI';
SID SERIAL# PADDR STATUS
---------- ---------- ---------------- --------
234 14409 C0000000B2C750B8 KILLED
245 14374 C0000000B2BAB748 INACTIVE
SQL> alter system kill session '245,14374' immediate;
System altered
SQL> select sid,serial#,paddr,status from v$session where username='SHIYIHAI';
SID SERIAL# PADDR STATUS
---------- ---------- ---------------- --------
234 14409 C0000000B2C750B8 KILLED
245 14374 C0000000B2C750B8 KILLED
SQL>
我們知道很多時候被kill掉的session並不能馬上釋放資源,我們需要從os上kill掉對應的程式,但由於session的paddr被修改為虛擬地址了,導致無法關聯v$process,找不到程式的spid程式號.此時我們可以執行如下查詢:
SQL> SELECT s.username,s.status,
2 x.ADDR,x.KSLLAPSC,x.KSLLAPSN,x.KSLLASPO,x.KSLLID1R,x.KSLLRTYP,
3 decode(bitand (x.ksuprflg,2),0,null,1)
4 FROM x$ksupr x,v$session s
5 WHERE s.paddr(+)=x.addr
6 and bitand(ksspaflg,1)!=0
7 and s.status is null;
USERNAME STATUS ADDR KSLLAPSC KSLLAPSN KSLLASPO KSLLID1R KSLLRTYP DECODE(BITAND(X.KSUPRFLG,2),0,
------------------------------ -------- ---------------- ---------- ---------- ------------ ---------- -------- ------------------------------
C0000000B2B58D08 0 0 0
C0000000B2BA4688 298 9 4669 0
C0000000B2BAB748 1 16 4675 197 EV
C0000000B2BADB28 1 16 4675 197 EV
SQL>
或查詢如下的語句:
SQL> select p.addr from v$process p where pid <> 1
2 minus
3 select s.paddr from v$session s;
ADDR
----------------
C0000000B2BA4688
C0000000B2BAB748
C0000000B2BADB28
SQL>
從查詢結果中可發現被kill掉的session對應的程式地址.然後透過程式地址來查詢對應的程式號,見如下的查詢:
SQL> select spid from v$process where addr in ('C0000000B2BAB748','C0000000B2BADB28');
SPID
------------
13013
13015
最後在作業系統上執行"kill -9 13013"和"kill -9 13015"即可.
[@more@]
來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/38542/viewspace-897744/,如需轉載,請註明出處,否則將追究法律責任。
相關文章
- Oracle中的Connect、session、process的區別OracleSession
- ORACLE SESSION 和 PROCESSOracleSession
- Oracle中Kill session的研究OracleSession
- 在Oracle中session和process的區別(轉)OracleSession
- Oracle中Kill session的研究 for oracle -- 轉OracleSession
- oracle session和process的關係OracleSession
- 關於v$process與v$session中process的理解Session
- 關於oracle中session跟蹤的總結OracleSession
- 修改Oracle process 和 session 的方法--摘OracleSession
- oracle session和process的關係 .轉自CSDNOracleSession
- oracle session(會話) 跟蹤OracleSession會話
- oracle中修改processOracle
- 用oracle trace 來跟蹤sessionOracleSession
- alter session set events /Oracle跟蹤SessionOracle
- process和session的總結Session
- session,connect,processSession
- 用oracle trace 來跟蹤session 活動OracleSession
- v$process和v$session中欄位解釋Session
- oracle一個process對應多個session測試OracleSession
- ORACLE中的KILLED SESSIONOracleSession
- v$session.PROCESS/V$process.SPID含義Session
- Oracle中Kill sessionOracleSession
- Oracle 動態效能表 v$session & v$process各個欄位的說明OracleSession
- Oracle中診斷阻塞的sessionOracleSession
- Oracle V$SESSION中的常用列OracleSession
- 處理Oracle Session中的鎖OracleSession
- 大話Oracle中的kill sessionOracleSession
- 玩轉跟蹤(to owner session、other session)Session
- Oracle SQL 跟蹤 --- dbms_system.set_sql_trace_in_sessionOracleSQLSession
- Oracle中Kill session [轉]OracleSession
- process/session/connection的一些問題Session
- connection session process的聯絡與區別Session
- [Shell] Linux monitor OS process and DB sessionLinuxSession
- 在oracle裡把backugroupd process叫做oracle的deamon process咋樣Oracle
- oracle中的processes,session,transaction引數OracleSession
- Oracle backgroud ProcessOracle
- 6.Monitor Linux OS process and DB sessionLinuxSession
- session_cached_cursors的研究Session