Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I see queries that are executed against Oracle?

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 ?

like image 509
vld_apos Avatar asked Jul 13 '10 14:07

vld_apos


People also ask

How do you see what queries are running in Oracle?

The following query may give you the list of running SQL ( SQL_ID ) from Active Sessions: select inst_id, program, module, SQL_ID, machine from gv$session where type!=


2 Answers

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'
like image 164
bhangm Avatar answered Oct 25 '22 06:10

bhangm


This query will show queries that are currently running:

select sql_text from v$sqlarea where users_executing > 0;

See documentation of V$SQLAREA

like image 39
Tony Andrews Avatar answered Oct 25 '22 06:10

Tony Andrews