关于v$process与v$session o…

来源:互联网 发布:淘宝店铺联盟在哪里 编辑:程序博客网 时间:2024/06/05 00:45
Good Test
原文地址:oracle">关于v$process与v$session oracle作者:AngleBoye
关于v$process与v$session中process的理解

说明
v$session有个process字段,V$PROCESS有个SPID字段,这两个字段是不是一个意思呢?是不是都代表会话的操作系统进程呢?
官方文档上的解释:
SPID     VARCHAR2(12)  Operatingsystem process identifier
PROCESS  VARCHAR2(9)  Operating system client process ID

本文以数据库服务器安装在unix上为例进行说明。
V$PROCESS中的SPID表示的是操作系统的进程,v$session中的process表示客户端进程ID,即客户端进程在客户端机器上的进程ID号。一个表示客户端进程在客户端机器上的进程号,一个表示服务器进程在服务器上的进程号。
连接服务器的会话,发起会话的客户端进程可能是unix进程,也可能是windows进程。
-------------------
windows客户端进程
-------------------
例如,使用windows进程连接unix上的数据库,对应会话sid=35,对应客户端windows的988:5412
格式为"客户端PID:线程ID"。如"988:5412",
表明连接到数据库的客户端程序在客户计算机上的进程ID是 988 ,该进程内的5412号线程执行了数据库的连接。
set linesize 200
col machine format a30
col program format a50
col status format a10
col username format a10
select machine,program,username,status from v$session wheresid=&oracle_sid;

Enter value for oracle_sid: 35
old   1: selectmachine,program,username,status,process from v$session wheresid=&oracle_sid
new   1: selectmachine,program,username,status,process from v$session wheresid=35
MACHINE                 PROGRAM       USERNAME  STATUS    PROCESS
------------------------------ ---------------- -------------------- ------------
WORKGROUPHXC            plsqldev.exe    SYS      INACTIVE  988:5412

sid=35对应的unix数据库服务器上的服务器进程为 16805
SQL> select spid os_sid
    from v$process
   where addr = (select paddr from v$session wheresid = &oracle_sid);
Enter value for oracle_sid: 35
old  3:  where addr= (select paddr from v$session where sid =&oracle_sid)
new  3:  where addr= (select paddr from v$session where sid = 35)
OS_SID
------------
16805

[monitor:/]#ps -ef|grep 16805
    root 1727817174  0 14:27:23pts/tA    0:00 grep 16805
  oracle 16805     014:22:56 ?        0:00oraclerobin (LOCAL=NO)
[monitor:/]#


-------------------
Unix客户端进程
-------------------
再来看看unix客户端连接到unix服务器端的实例
连接服务器的会话sid=260
对应的客户端进程号为 26349
SQL> set linesize 200
SQL> col machine format a30
SQL> col program format a50
SQL> col status format a10
SQL> col username format a10
SQL>
SQL> select machine,program,username,status,processfrom v$session where sid=&oracle_sid;
Enter value for oracle_sid: 260
old   1: selectmachine,program,username,status,process from v$session wheresid=&oracle_sid
new   1: selectmachine,program,username,status,process from v$session wheresid=260
MACHINE  PROGRAM                    USERNAME  STATUS    PROCESS
--------- ------------------------------------ -------------------- ------------
zhzw01   [email=accountrefresh@zhzw01]accountrefresh@zhzw01[/email] (TNSV1-V3)    BILL_GATHEACTIVER    26349
            
            

对应的服务器进程号为 13472
SQL> select spid os_sid
    from v$process
   where addr = (select paddr from v$session wheresid = &oracle_sid);
Enter value fororacle_sid:  260
old  3:  where addr= (select paddr from v$session where sid =&oracle_sid)
new  3:  where addr= (select paddr from v$session where sid=  260)
OS_SID
------------
13472

hnzzzw01:/arraybill/home/oracle$ ps -ef|grep 13472
orabill 25649 25452  0 14:22:56pts/ta    0:00 grep 13472
orabill 13472    1 25510月        30969:04oraclehnbill (LOCAL=NO)
hnzzzw01:/arraybill/home/oracle$


-------------------
说明
-------------------
如果是通过sid,查询到进程spid,使用操作系统命令直接杀掉进程
kill -9 spid
注意,是 spid,而不是v$session中对应的客户端的process,别杀错了进程。
 
注:同时也可以通过下面的脚本来查找存储过程进程ID:
 

CREATE OR REPLACE  PROCEDUREP_Test   as
myRecnum number(10);
mySID number(10);
mySpid number(10);
cursor c_test is SELECT SID FROM V$ACCESS WHERE OWNER='AAA' ANDobject = 'PROC1' and type = 'PROCEDURE';
begin
  myRecnum:=0;
  SELECT count(*) into myRecnum FROMV$DB_OBJECT_CACHE WHERE OWNER='AAA' AND name = 'PROC1'and  LOCKS <>'0';
  if myRecnum > 0 then
    openc_test;
    fetch c_testinto mySID;
    whilec_test%FOUND LOOP
       select spid into mySpid from v$session s,v$process p wheres.paddr=p.addr and s.sid = mySID;
       --杀掉进程
       orakill Oracle_SID mySpid;
       fetch c_test into mySID;
    endLOOP;
    closec_test;
  end if;
  end;
0 0
原创粉丝点击