Solved

Find sql text and user by pid and sid

Posted on 2006-07-13
8
2,004 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
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
Thank you very much!
0
 
LVL 14

Expert Comment

by:sathyagiri
Comment Utility
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.

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
Access Required to Import Oracle Database Table 3 43
UNIX SCP 5 45
automatic email alert 1 20
sql query 9 18
Note: this article covers simple compression. Oracle introduced in version 11g release 2 a new feature called Advanced Compression which is not covered here. General principle of Oracle compression Oracle compression is a way of reducing the d…
Configuring and using Oracle Database Gateway for ODBC Introduction First, a brief summary of what a Database Gateway is.  A Gateway is a set of driver agents and configurations that allow an Oracle database to communicate with other platforms…
This video shows, step by step, how to configure Oracle Heterogeneous Services via the Generic Gateway Agent in order to make a connection from an Oracle session and access a remote SQL Server database table.
This video shows how to copy an entire tablespace from one database to another database using Transportable Tablespace functionality.

771 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

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now