首页 > 数据库 > Oracle > Oracle生成指定 SQL 语句的统计报表
这项统计专门用来分析某条指定的 SQL 语句,通过 awrsqrpt.sql 脚本,awr 能够生成指 定 sql(曾经执行过的 SQL)的执行计划,消耗的资源等等信息,有助于 DBA 进行 SQL 调优。
具体操作如下,首先还是执行生成脚本:
SQL> @$ORACLE_HOME/rdbms/admin/awrsqrpt.sql
Current Instance
~~~~~~~~~~~~~~~~
|
DB Id |
DB Name |
Inst Num Instance |
|
----------- ------------ -------- ------------ |
||
|
3812548755 TEST08 |
1 test08 |
|
|
|
|
|
Specify the Report Type
~~~~~~~~~~~~~~~~~~~~~~~
Would you like an HTML report, or a plain text report?
Enter 'html' for an HTML report, or 'text' for plain text
Defaults to 'html'
Enter value for report_type: html
选择生成的报表格式,没啥说的,就默认的 html 格式吧。
Type Specified: html
Instances in this Workload Repository schema
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
DB Id |
Inst Num DB Name |
Instance |
Host |
|
------------ -------- ------------ ------------ ------------ |
|
||
|
* 3812548755 |
1 TEST08 |
test08 |
yans1 |
|
Using 3812548755 for database Id |
|
|
|
|
Using |
1 for instance number |
|
|
|
|
|
|
|
Specify the number of days of snapshots to choose from
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Entering the number of days (n) will result in the most recent
(n) days of snapshots being listed. Pressing <return> without specifying a number lists all completed snapshots.
Enter value for num_days: 2
指定报表快照的生成区间!
Listing the last 2 days of Completed Snapshots
|
Instance |
DB Name |
Snap Id |
Snap Started |
Level |
|
|
------------ ------------ --------- ------------------ ----- |
|
|
|||
|
test08 |
TEST08 |
7450 25 10 月 2009 00:00 |
1 |
||
|
|
|
7451 25 10 月 2009 01:00 |
1 |
||
|
|
|
7452 25 10 月 2009 02:00 |
1 |
||
|
|
|
7453 25 10 月 2009 03:00 |
1 |
||
|
|
|
7454 25 10 月 2009 04:00 |
1 |
||
|
|
|
7455 25 10 月 2009 05:00 |
1 |
||
|
|
|
7456 25 10 月 2009 06:00 |
1 |
||
|
|
|
7457 25 10 月 2009 07:00 |
1 |
||
|
|
|
7458 25 10 月 2009 08:00 |
1 |
||
|
|
|
7459 25 10 月 2009 09:00 |
1 |
||
|
|
|
7460 25 10 月 2009 10:00 |
1 |
||
|
|
|
7461 25 10 月 2009 11:00 |
1 |
||
|
|
|
7462 25 10 月 2009 12:00 |
1 |
||
|
|
|
7463 25 10 月 2009 13:00 |
1 |
||
|
|
|
7464 25 10 月 2009 14:00 |
1 |
||
|
|
|
7465 25 10 月 2009 15:00 |
1 |
||
|
|
|
7466 25 10 月 2009 16:00 |
1 |
||
|
|
|
7467 25 10 月 2009 17:00 |
1 |
||
|
|
|
7468 25 10 月 2009 18:00 |
1 |
||
|
|
|
7469 25 10 月 2009 19:00 |
1 |
||
|
|
|
7470 25 10 月 2009 20:00 |
1 |
||
|
|
|
7471 25 10 月 2009 21:00 |
1 |
||
|
|
|
7472 25 10 月 2009 22:00 |
1 |
||
|
|
|
7473 25 10 月 2009 23:00 |
1 |
||
|
|
|
7474 26 10 月 2009 00:00 |
1 |
||
|
|
|
7475 26 10 月 2009 01:00 |
1 |
||
|
|
|
7476 26 10 月 2009 02:00 |
1 |
||
|
|
|
7477 26 10 月 2009 03:00 |
1 |
||
|
|
|
7478 26 10 月 2009 04:00 |
1 |
||
|
|
|
7479 26 10 月 2009 05:00 |
1 |
||
|
|
|
7480 26 10 月 2009 06:00 |
1 |
||
|
|
|
7481 26 10 月 2009 07:00 |
1 |
||
|
|
|
7482 26 10 月 2009 08:00 |
1 |
||
|
|
|
7483 26 10 月 2009 09:00 |
1 |
||
|
|
|
7484 26 10 月 2009 10:00 |
1 |
||
|
|
|
|
|
|
|
Specify the Begin and End Snapshot Ids
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Enter value for begin_snap: 7451
Begin Snapshot Id specified: 7451
Enter value for end_snap: 7475
End Snapshot Id specified: 7475
指定开始和结束的快照 ID:
Specify the SQL Id
~~~~~~~~~~~~~~~~~~
Enter value for sql_id: a51q9un8j1kv6
注意喽,这里要指定分析的 SQL_ID,你可能想问,要分析的 SQL ID 从何而来呢?一 般来说,提出这种问题说明你还未操作过 awr 或看到一条 SQL。为什么这么说呢,因为一 般来讲,获取问题 SQL 的途径要么是通过 V$SQL( 及其它相关视图) ,要么是通过 AWR/STATSPACK 等工具,而这些方式找到 SQL 语句时,只要你再稍微拿眼神的旁光这么 一扫,就会发现在语句的旁边有一条 SQL ID 静静的矗立着:)
更多信息参考http://www.infocool.net/Oracle/index.htm
SQL ID specified: a51q9un8j1kv6
Specify the Report Name
~~~~~~~~~~~~~~~~~~~~~~~
The default report file name is awrsqlrpt_1_7451_7475.html. To use this name, press <return> to continue, otherwise enter an alternative.
Enter value for report_name: awr_sqlrpt_1_7451_7475.html
Using the report name awr_sqlrpt_1_7451_7475.html
<HTML><HEAD><TITLE>AWR SQL Report</TITLE><style type="text/css">
............
................
输入完 SQL ID 后,短暂等待几秒钟,报告就生成了。
来自 “ ITPUB博客 ” ,链接:https://blog.itpub.net/1700919/viewspace-2115009/ ,如需转载,请注明出处,否则将追究法律责任。