關於oracle裡的process總結

dbhelper發表於2014-11-27
感覺需要對process做一個簡單的總結。準備瞭如下的測試場景。
session在服務端請求
先用sqlplus / as sysdba在服務端登入。
SQL> show user
USER is "SYS"
得到當前的session為5860.

SQL> select sid from v$mystat where rownum<2;
       SID
----------
      5860
得到對應的Process。這個其實就是客戶端對應的process,因為是從服務端登入,所以在服務端應該會有兩個process來對應,一個相當於客戶端,一個相當於服務端paddr是process對應的記憶體地址,在查詢v$process的很有用。
SQL> select sid,username,process,paddr  from v$session where sid=5860;
       SID USERNAME                       PROCESS                  PADDR
---------- ------------------------------ ------------------------ ----------------
      5860 SYS                            28490                    000000035977B488
先來驗證一下客戶端的process 28490是不是存在。可以看到,28490是透過sqlplus的方式登入的。而且是另外一個連線的父程式。這個程式就是我們需要查詢的在服務端存在的對映程式。
SQL> host ps -ef|grep 28490
oratestdb  6741 28490  0 14:48 pts/1    00:00:00 /bin/bash -c ps -ef|grep 28490
oratestdb  6743  6741  0 14:48 pts/1    00:00:00 grep 28490
oratestdb 28490  4017  0 14:45 pts/1    00:00:00 sqlplus   as sysdba
oratestdb 28491 28490  0 14:45 ?        00:00:00 oraclePETtest1 (DESCRIPTION=(LOCAL=YES)(ADDRESS=(PROTOCOL=beq)))

我們來查詢v$process,看process是不是存在28491,spid就是對應的攝影程式,pid是資料庫內部的程式標示。
檢視程式明細,可以看到使用的bequence協議。

SQL> select pid,spid from v$process where addr='000000035977B488';  
       PID SPID
---------- ------------------------
        31 28491
SQL> host ps -ef|grep 28491
oratestdb 14578 28490  0 14:50 pts/1    00:00:00 /bin/bash -c ps -ef|grep 28491
oratestdb 14580 14578  0 14:50 pts/1    00:00:00 grep 28491
oratestdb 28491 28490  0 14:45 ?        00:00:00 oraclePETtest1 (DESCRIPTION=(LOCAL=YES)(ADDRESS=(PROTOCOL=beq)))

再來看另外一個場景。

session在客戶端請求

透過sqlplus從客戶端登陸。

#############
 select sid from v$mystat where rownum<2;
       SID
----------
      6049
      
 select sid,username,process,paddr  from v$session where sid=6049
SQL> /
可以看到對應的Process是824. 這個就是客戶端所在的機器對應的process。
       SID USERNAME                       PROCESS                  PADDR
---------- ------------------------------ ------------------------ ----------------
      6049 JIANRONG                       824                    000000035977C508
SQL> host ps -ef|grep 824
oraccbs1   824 30352  0 17:05 pts/1    00:00:00 sqlplus                          
root      3824  3051  0  2013 ?        00:00:00 [aio/29]
oraccbs1 11079   824  0 17:06 pts/1    00:00:00 /bin/bash -c ps -ef|grep 824
oraccbs1 11082 11079  0 17:06 pts/1    00:00:00 grep 824
檢視服務端對應的程式,是17175
SQL> select pid,spid ,username from v$process where addr='000000035977C508';
       PID SPID                     USERNAME
---------- ------------------------ ---------------
        32 17175                    oratestdb


登入服務端,檢視程式情況,與客戶端的場景不同的是,17175的父程式是1,為root根程式。
oratestdb@ccbdbpt4:/opt/app/oracle/dbtestspt1/oratestdb> ps -ef|grep 17175
oratestdb 17175     1  0 17:05 ?        00:00:00 oraclePETtest1 (LOCAL=NO)
oratestdb 27196 24714  0 17:07 pts/1    00:00:00 grep 17175


對於客戶端場景和服務端場景來說,如果一定要刨根問底的看某個session(比如 session 824)的父程式情況。可以看到最終的process 父程式還是1.
oratest1@:/opt/app/oracle/dbtestpt1/oratest1> ps -ef|grep 30352
oratest1   824 30352  0 17:05 pts/1    00:00:00 sqlplus                          
oratest1 20500 20060  0 17:23 pts/1    00:00:00 grep 30352
oratest1 30352 30347  0 16:34 pts/1    00:00:00 -bash
oratest1@:/opt/app/oracle/dbtestpt1/oratest1> ps -ef|grep 30347
oratest1 21993 20060  0 17:23 pts/1    00:00:00 grep 30347
oratest1 30347 29705  0 16:34 ?        00:00:00 sshd: oratest1@pts/1
oratest1 30352 30347  0 16:34 pts/1    00:00:00 -bash
oratest1@:/opt/app/oracle/dbtestpt1/oratest1> ps -ef|grep 29705
oratest1 23945 20060  0 17:23 pts/1    00:00:00 grep 29705
root     29705 25298  0 16:34 ?        00:00:00 sshd: oratest1 [priv]
oratest1 30347 29705  0 16:34 ?        00:00:00 sshd: oratest1@pts/1
oratest1@:/opt/app/oracle/dbtestpt1/oratest1> ps -ef|grep 25298
root     25298     1  0  2013 ?        00:00:03 /usr/sbin/sshd
oratest1 26659 20060  0 17:24 pts/1    00:00:00 grep 25298
root     29705 25298  0 16:34 ?        00:00:00 sshd: oratest1 [priv]



來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/8494287/viewspace-1349356/,如需轉載,請註明出處,否則將追究法律責任。

相關文章