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

发布于 2024-08-16 10:21:16 字数 138 浏览 6 评论 0原文

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

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

有什么方法可以查看应用程序在过去 10 分钟内发出的所有查询吗?

I have an ASP.NET application that uses Oracle for persistence and queries it via ADO.NET and stored procedures.

I have the full version of TOAD and administrative rights to the database.

Is there any way to view all queries issued by the application over the last 10 minutes?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

挖个坑埋了你 2024-08-23 10:21:17

我不知道过去 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

I don't know about over the past 10 minutes, but if you use the Session Browser (off the toolbar, or Database Menu -> Monitor -> Session Browser) you can view the current statement of a connected user (expand w3wp.exe, then sort by machine name to find the correct connections), then just keep pressing the refresh button as you navigate through your app.

Breaking away from the confines of the TOAD GUI, you could try manually querying v$sqlarea:

  select * 
    from v$sqlarea
   where upper(module) = 'W3WP.EXE'
     and parsing_schema_name = 'MY_CONNECTING_SCHEMA'
order by last_active_time desc
作死小能手 2024-08-23 10:21:17

您可能不知道应用程序用户会话的 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')
/

You maybe don't know the SID of your applications user session. But you certainly know the schema owner of the objects, the applications is accessing.

To restrict your result by time you can use awr snapshots. (automatic workload repository)

More about 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')
/
避讳 2024-08-23 10:21:16

这是我用来检查慢速查询的查询:(可能会让您开始)

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;

Here is a query I use to examine slow queries: (Might get you started)

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;
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文