开发者

How can I see queries that are executed against Oracle?

开发者 https://www.devze.com 2023-01-07 15:42 出处:网络
I need to see the queries that are being sent to Oracle to execute them. Can someone give me 开发者_高级运维specific detailed instructions on how to do this ?If you want to see the queries from a spec

I need to see the queries that are being sent to Oracle to execute them. Can someone give me 开发者_高级运维specific detailed instructions on how to do this ?


If you want to see the queries from a specific user, you can use this (assuming you have privileges to query v$session and v$sqlarea (usually through SELECT_CATALOG_ROLE)

SELECT sess.sid,
       sess.username,
       sqla.optimizer_mode,
       sqla.hash_value,
       sqla.address,
       sqla.cpu_time,
       sqla.elapsed_time,
       sqla.sql_text
  FROM v$sqlarea sqla, v$session sess
 WHERE sess.sql_hash_value = sqla.hash_value
   AND sess.sql_address = sqla.address
   AND sess.username = 'SCOTT'

Replace SCOTT with the appropriate username in your system

Output:

 544 SCOTT      ALL_ROWS   2004330732 07000001064088E8         89391       131836 SELECT sess.sid,        sess.username,
                                                                                        sqla.optimizer_mode,        sqla.h
                                                                                  ash_value,        sqla.address,        s
                                                                                  qla.cpu_time,        sqla.elapsed_time,
                                                                                         sqla.sql_text   FROM v$sqlarea sq
                                                                                  la, v$session sess  WHERE sess.sql_hash_
                                                                                  value = sqla.hash_value    AND sess.sql_
                                                                                  address = sqla.address    AND sess.usern
                                                                                  ame = 'SCOTT'


This query will show queries that are currently running:

select sql_text from v$sqlarea where users_executing > 0;

See documentation of V$SQLAREA


You can check and get the data if you have access to these two oracle tables/views (v$sqlarea & v$sqltext), Also accoridng to your need you can also modify the query and add A.cpu_time, A.elapsed_time if required.

Query -

 SELECT A.SQL_ID,
         A.FIRST_LOAD_TIME,
         A.SQL_TEXT,
         A.SQL_FULLTEXT
    FROM v$sqlarea A, v$sqltext B
   WHERE     A.PARSING_SCHEMA_NAME = 'TESTUSER'  --YOUR USERNAME
         AND A.SQL_ID = B.SQL_ID
         AND A.HASH_VALUE = B.HASH_VALUE
ORDER BY A.FIRST_LOAD_TIME DESC

Output -

How can I see queries that are executed against Oracle?

0

精彩评论

暂无评论...
验证码 换一张
取 消