Solved

Find sql text and user by pid and sid

Posted on 2006-07-13
8
2,080 Views
Last Modified: 2008-01-09

 Hi Guys,

Does anyone has a script of how to find most offensive SQL statements by sid and pid?


Thanks,
Mia
0
Comment
Question by:milanushka
  • 3
  • 2
8 Comments
 
LVL 34

Accepted Solution

by:
johnsone earned 25 total points
ID: 17100575
To get text by sid:

select sql_text
from v$session a,
      v$sqltext b
where a.sql_hash_value = b.hash_value and
     a.sid = <sid>
order by piece;

To get text by pid:

select sql_text
from v$process a,
     v$session b,
     v$sql_text c
where a.addr = b.paddr and
     b.sql_hash_value = c.hash_value and
    a.spid = <pid>
order by piece;
0
 

Author Comment

by:milanushka
ID: 17100609
Thank you very much.
I have a scrip that shows most offencive sql. Is there a way to modify that script to show sid or pid

SET LINESIZE 500
SET PAGESIZE 1000
SET VERIFY OFF

SELECT *
FROM   (SELECT Substr(a.sql_text,1,100) sql_text,
               Trunc(a.disk_reads/Decode(a.executions,0,1,a.executions)) reads_per_execution,
               a.buffer_gets,
               a.disk_reads,
               a.executions,
               a.sorts,
               a.address
        FROM   v$sqlarea a
        ORDER BY 2 DESC)
WHERE  rownum <= 100;

SET PAGESIZE 14


Thanks again

Mia
0
 
LVL 14

Expert Comment

by:sathyagiri
ID: 17101211
SELECT *
FROM   (SELECT Substr(a.sql_text,1,100) sql_text,
               Trunc(a.disk_reads/Decode(a.executions,0,1,a.executions)) reads_per_execution,
               a.buffer_gets,
               a.disk_reads,
               a.executions,
               a.sorts,
               a.address,b.sid,c.spid
        FROM   v$sqlarea a ,V$SESSION b, V$PROCESS WHERE a.hash_value =  b.hash_value and a.addr = b.paddr
        ORDER BY 2 DESC)
WHERE  rownum <= 100;
0
PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

 
LVL 14

Assisted Solution

by:sathyagiri
sathyagiri earned 25 total points
ID: 17101233
Use this
SELECT *
FROM   (SELECT Substr(a.sql_text,1,100) sql_text,
               Trunc(a.disk_reads/Decode(a.executions,0,1,a.executions)) reads_per_execution,
               a.buffer_gets,
               a.disk_reads,
               a.executions,
               a.sorts,
               a.address,b.sid,c.spid
        FROM   v$sqlarea a ,V$SESSION b, V$PROCESS c WHERE a.hash_value =  b.sql_hash_value and c.addr = b.paddr
        ORDER BY 2 DESC)
WHERE  rownum <= 100
/
0
 

Author Comment

by:milanushka
ID: 17101242
Thank you very much!
0
 
LVL 14

Expert Comment

by:sathyagiri
ID: 17112331
Please remember  to accept answer
0

Featured Post

PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Background In several of the companies I have worked for, I noticed that corporate reporting is off loaded from the production database and done mainly on a clone database which needs to be kept up to date daily by various means, be it a logical…
How to Unravel a Tricky Query Introduction If you browse through the Oracle zones or any of the other database-related zones you'll come across some complicated solutions and sometimes you'll just have to wonder how anyone came up with them.  â€¦
This video shows how to Export data from an Oracle database using the Original Export Utility.  The corresponding Import utility, which works the same way is referenced, but not demonstrated.
This video shows how to configure and send email from and Oracle database using both UTL_SMTP and UTL_MAIL, as well as comparing UTL_SMTP to a manual SMTP conversation with a mail server.

777 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question