Oracle DBA:有什么方法可以查看我的ASP.NET应用程序运行的查询?

时间:2009-12-31 16:54:25

标签: asp.net oracle profiling toad

我有一个使用Oracle进行持久化的ASP.NET应用程序,并通过ADO.NET和存储过程对其进行查询。

我拥有完整版的TOAD和数据库的管理权限。

有没有办法查看应用程序在过去10分钟内发出的所有查询?

3 个答案:

答案 0 :(得分:2)

我不知道过去10分钟,但如果您使用会话浏览器(在工具栏上,或数据库菜单 - >监视器 - >会话浏览器),您可以查看已连接用户的当前语句(展开w3wp.exe,然后按机器名排序以找到正确的连接),然后在浏览应用程序时按住刷新按钮。

远离TOAD GUI的范围,您可以尝试手动查询v$sqlarea

  select * 
    from v$sqlarea
   where upper(module) = 'W3WP.EXE'
     and parsing_schema_name = 'MY_CONNECTING_SCHEMA'
order by last_active_time desc

答案 1 :(得分:2)

这是我用来检查慢查询的查询:(可能让你入门)

SELECT   username, sql_text, elapsed_time, executions, optimizer_cost, loads,
         fetches, rows_processed,
         DECODE (command_type,
                 2, 'Insert',
                 3, 'Select',
                 6, 'Update',
                 7, 'Delete',
                 26, 'Lock Table',
                 35, 'Alter Database',
                 42, 'Alter Session',
                 44, 'Commit',
                 45, 'Rollback',
                 46, 'Savepoint',
                 47, 'Begin/Declare',
                 command_type
                ) AS cmdtype,
         first_load_time, last_load_time, module
    FROM v$sql, v$session_longops
   --longops is a view of statements that took longer than 6 seconds
WHERE    sql_address(+) = address AND sql_hash_value(+) = hash_value
ORDER BY elapsed_time DESC, executions, address, hash_value, child_number;

答案 2 :(得分:1)

您可能不知道应用程序用户会话的SID。但是你肯定知道对象的模式所有者,应用程序正在访问。

要按时间限制结果,可以使用awr快照。 (自动工作负载存储库)

有关AWR的更多信息:http://download.oracle.com/docs/cd/B19306_01/server.102/b14211/autostat.htm#PFGRF02601

--Create a snapshot
exec dbms_workload_repository.create_snapshot;

--Wait 10min and create another snapshot;
exec dbms_workload_repository.create_snapshot;

--This Statement does the following:
--1. Get the recent two Snapshot IDs
--2. Select all SQL IDs which are execute between the last two snapshots
--3. Filter the SQL IDs which are accessing objects of a certain owner (Substitute 'APP_OWNER' with the schema owner of your application)
--4. Select the SQL text of all these SQL IDs

SELECT sql_id,
       sql_text
FROM   dba_hist_sqltext
WHERE  sql_id IN (SELECT DISTINCT sql_id
                  FROM   dba_hist_sql_plan
                  WHERE  sql_id IN (SELECT sql_id
                                    FROM   dba_hist_sqlstat
                                    WHERE  snap_id BETWEEN (SELECT max(snap_id) - 1
                                                            FROM   dba_hist_snapshot) AND (SELECT max(snap_id)
                                                                                           FROM   dba_hist_snapshot))
                         AND object_owner = 'APP_OWNER')
/