Advertisement

Thursday, January 17, 2019

Oracle Database - Scripts - SID to PID and PID to SID

In this blog I am going to cover a simple script which converts the SID  you mentioned to OS PID . 

SID to PID
set lines 500 pages 500
column sid format 99999
column spid format 99999
column program format a30
column osuser format a30

select a.sid,b.spid,a.username,a.osuser
from v$session a,
v$process b
where a.paddr = b.addr
and a.sid = &SID
order by b.spid;

When Prompted Enter SID


  1  select a.sid,b.spid,a.username,a.osuser
  2  from v$session a,
  3  v$process b
  4  where a.paddr = b.addr
  5  and a.sid = &SID
  6* order by b.spid
Enter value for sid: 31
old   5: and a.sid = &SID
new   5: and a.sid = 31

   SID SPID                     USERNAME                                           OSUSER
------ ------------------------ -------------------------------------------------- ------------------------------

    31 9936                     AS                                                 iisuser



PID to SID

set lines 500 pages 500
column sid format 99999
column spid format 99999
column program format a30
column osuser format a30

select a.sid,b.spid,a.username,a.osuser
from v$session a,
v$process b
where a.paddr = b.addr
and b.spid = &PID
order by b.spid;

When Prompted Enter PID

  1  select a.sid,b.spid,a.username,a.osuser
  2  from v$session a,
  3  v$process b
  4  where a.paddr = b.addr
  5  and b.spid = &PID
  6* order by b.spid
Enter value for pid: 9936
old   5: and b.spid = &PID
new   5: and b.spid = 9936

   SID SPID                     USERNAME                                           OSUSER
------ ------------------------ -------------------------------------------------- ------------------------------

    31 9936                     AS                                                 iisuser



To List all SIDs with their PIDs
set lines 500 pages 500
column sid format 99999
column spid format 99999
column program format a30
column osuser format a30

select a.sid,b.spid,a.username,a.osuser
from v$session a,
v$process b
where a.paddr = b.addr

order by b.spid




No comments:
Write comments