Saturday, May 21, 2016

How to find Session ID/ SQL ID/ SQL Statement Using OS Process ID

1. It will show you the basic Session Information.

SELECT P.SPID OS_PROCESS_ID,
      S.SID SESSION_ID,
      S.SERIAL#,
      S.USERNAME,
      S.STATUS,
      S.LAST_CALL_ET,
      P.PROGRAM,
      P.TERMINAL,
      LOGON_TIME,
      MODULE,
      S.OSUSER
 FROM GV$PROCESS P, GV$SESSION S
WHERE S.PADDR = P.ADDR
AND S.INST_ID=P.INST_ID
AND P.SPID=&Process_ID
ORDER BY S.INST_ID;

2. It Will Show You the SQL ID which SQL Statements currently Executing.

 SELECT S.SQL_ID
  FROM GV$PROCESS P, GV$SESSION S
 WHERE S.PADDR = P.ADDR
 AND S.INST_ID=P.INST_ID
 AND  P.SPID=&Process_ID
 ORDER BY S.INST_ID;

3. It Will Show You the SQL Statements Details which SQL Statements are currently Running.

SELECT *
FROM GV$SQLAREA
WHERE SQL_ID =
(SELECT S.SQL_ID
FROM GV$PROCESS P, GV$SESSION S
WHERE     S.PADDR = P.ADDR
AND S.INST_ID = P.INST_ID
AND P.SPID = &Process_ID)
ORDER BY INST_ID;


No comments:

Post a Comment