oracle性能调优之--Oracle 10g AWR 配置

来源:互联网 发布:cocos2d lua 麻将源码 编辑:程序博客网 时间:2024/05/22 01:58

 

一、ASH和AWR的故事

1.1  关于ASH

我们都知道,用户在ORACLE数据库中执行操作时,必然要创建相应的连接和会话,其中,所有当前的会话信息都保存在动态性能视图V$SESSION中,通过该视图,DBA可以查看用户实际执行的操作,或者当前的等待事件等。通常这部分信息是调优过程中的关键信息,不过,一旦连接断开。会话信息就会被同时从V$SESSION及其它相关视图中清除,也就是说,用户执行完操作走人,而你(DBA),如果不能在当前逮到他,过了这点,就不知道它曾经做过什么了。

10g 版本中,ORACLE又新增加了一个视图(其它是若干,不过咱们还是以session为引子说):V$ACTIVE_SESSION_HISTORY,看名字就知道,就是活动会话的历史记录,这下,即使用户操作完成后,断开了连接也不怕,因为其会话的情况已经被记录了下来,这项特性就是ASH了,全称与视图名相同,正是:ACTIVE SESSION HISTORY。

ASH 每秒钟收集一次当前处于非空闲等待事件的、活动状态的、session的信息,并保存在V$ACTIVE_SESSION_HISTORY视图中,我们(应该以及必须)知道,动态性能视图其实上是ORACLE自行构造的一堆存在于SGA内存区的虚表,就是说,ASH的数据是保存在内存里的,实际上,ORACLE分配给ASH的空间并不是无限大(更何况ORACLE自身管理的内存空间也不是无限大),查看ASH可供使用的内存空间,可以通过如下SQL:

SQL> select pool, name, bytes/1024/1024  Mb  From v$sgastat where name like ¨ASH %¨;

 

POOL         NAME                        Mb

------------ -------------------------- ---------------

shared pool  ASH buffers                           15.5

直白的讲 ,V$ACTIVE_SESSION_HISTORY中能够记录多少会话信息, 一方面取决于该数据库的SGA 分配给ASH buffers的大小 ,另一方面取决于数据库的启动和关闭(重启数据库时将重构SGA内存区)。这两方面的因素制约了V$ACTIVE_SESSION_HISTORY中能够保存的会话信息的能力,做为DBA,我们肯定是希望ASH尽可能多的保留关于会话的信息,但目前来看单纯依靠

V$ACTIVE_SESSION_HISTORY肯定无法实现这点,那怎么办呢?别担心,ORACLE又提供了AWR特性,ASH收集到的会话信息,是做为AWR中快照信息的一部分,被保存到了硬盘上。

1.2  关于AWR

AWR 是 Oracle  10g 版本 推出的新特性, 全称叫Automatic Workload Repository-自动负载信息库。 谈到这一特性呢,不得不先提Statspack,Statspack称的上是ORACLE世界里的老人了,不过毕竟年岁大了,腿脚虽然还算灵便,但效率不那么高了,用时髦话讲就是不能适应时代发展步伐,不能紧跟时代潮流,不能保持做为一名优秀党员的先进性,始终坚持带三个表的为DBA服务。但是,说到底Statspack还是为了党国事业奋斗了一辈子,在党内还是有势力有威信有地位有影响的四有老人,还有余热可以发挥, 虽然其在统计实时性方面,表现已不足以满足DBA多变的需求,依然 不能一下就将其拿下, 因此 ORACLE 采取渐进方式先 推出了AWR,说是辅助Statspack工作,其实明眼人一看就明了,这是新指定的接班人哪。

 

AWR 与前辈Statspack在职业定位方面是相同的,都是负责收集、处理并维护性能统计信息,用于检查和分析性能问题(甚至生成的报告格式都非常接近),AWR生成的统计数据即可以通过V$视图和DBA_*数据字典查看,也可以通过脚本来生成相应报表。谈到相比Statspack,AWR究竟在哪些方面有所提升呢,捡主要的讲就两条:自动+实时,至于功能上的些许提高,不过是因为AWR年轻腿脚利索罢了。

 

 

二、生成分析报表

AWR 是通过对比两次快照(snapshot)收集到的统计信息,来生成报表数据,生成的报表包括多个部分,这点与Statspack生成的报告非常类似。不过AWR在生成报告时,可以选择生成TXT或HTML两种格式的报告,相对来说,HTML更利于阅读,而TXT的适用性更广(即使在不能使用浏览器的机器上也能看)。

操作过Statspack的朋友都还记的,生成报告使用$ORACLE_HOME/rdbms/admin/spreport.sql脚本,到了AWR这片,操作步骤基本上相同,不过生成报告的脚本多了很多选择,包括:

  • awrrpt.sql :生成指定快照区间的统计报表;
  • awrrpti.sql :生成指定数据库实例,并且指定快照区间的统计报表;
  • awrsqlrpt.sql :生成指定快照区间,指定SQL语句(实际指定的是该语句的SQLID)的统计报表;
  • awrsqrpi.sql :生成指定数据库实例,指定快照区间的指定SQL语句的统计报表;
  • awrddrpt.sql :指定两个不同的时间周期,生成这两个周期的统计对比报表;
  • awrddrpi.sql :指定数据库实例,并指定两个的不同时间周期,生成这两个周期的统计对比报表;

下面的章节中,我们就来一一例举。

提示:与使用Statspack一样,要想让AWR收集到准确的统计信息,从而生成可靠的性能分析报告,必须将初始化参数STATISTICS_LEVEL的值设置为TYPICAL或ALL。

2.1 生成标准统计报表

过程并不复杂,下列操作中加粗的部分,是需要指定值的位置(注意,执行报表生成的用户必须拥有DBA角色):

JSSWEB> @$ORACLE_HOME/rdbms/admin/awrrpt.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

此处需指定生成的报表格式,有txt和html两种选择,默认情况下为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 without

specifying a number lists all completed snapshots.

Enter value for num_days: 2

此处需指定要读取多少天内的快照信息!

Listing the last 2 days of Completed Snapshots

Snap

Instance DB Name Snap Id Snap Started Level

------------ ------------ --------- ------------------ -----

test08 TEST08 7330 20 10 月 2009 00:00 1

7331 20 10 月 2009 01:00 1

7332 20 10 月 2009 02:00 1

7333 20 10 月 2009 03:00 1

7334 20 10 月 2009 04:00 1

7335 20 10 月 2009 05:01 1

7336 20 10 月 2009 06:00 1

7337 20 10 月 2009 07:01 1

7338 20 10 月 2009 08:00 1

7339 20 10 月 2009 09:00 1

7340 20 10 月 2009 10:00 1

7341 20 10 月 2009 11:00 1

7342 20 10 月 2009 12:00 1

7343 20 10 月 2009 13:00 1

7344 20 10 月 2009 14:00 1

7345 20 10 月 2009 15:00 1

7346 20 10 月 2009 16:00 1

7347 20 10 月 2009 17:00 1

7348 20 10 月 2009 18:00 1

7349 20 10 月 2009 19:00 1

7350 20 10 月 2009 20:00 1

7351 20 10 月 2009 21:00 1

7352 20 10 月 2009 22:00 1

7353 20 10 月 2009 23:00 1

7354 21 10 月 2009 00:00 1

7355 21 10 月 2009 01:00 1

7356 21 10 月 2009 02:00 1

7357 21 10 月 2009 03:00 1

7358 21 10 月 2009 04:00 1

7359 21 10 月 2009 05:00 1

7360 21 10 月 2009 06:00 1

7361 21 10 月 2009 07:00 1

7362 21 10 月 2009 08:00 1

7363 21 10 月 2009 09:00 1

7364 21 10 月 2009 10:00 1

7365 21 10 月 2009 11:00 1

7366 21 10 月 2009 12:00 1

7367 21 10 月 2009 13:00 1

7368 21 10 月 2009 14:00 1

Specify the Begin and End Snapshot Ids

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

Enter value for begin_snap: 7331

Begin Snapshot Id specified: 7331

Enter value for end_snap: 7355

End Snapshot Id specified: 7355

Specify the Report Name

~~~~~~~~~~~~~~~~~~~~~~~

The default report file name is awrrpt_1_7331_7355.html. To use this name,

press to continue, otherwise enter an alternative.

Enter value for report_name:

此处为要生成的报告指定一个文件名,默认会根据前面输入的snap_id生成一个文件名,比如这里生成的默认文件名为awrrpt_1_7331_7355.html,当然DBA可以根据实际情况对文件名进行自定义。这里三思偷个懒,就用默认文件名好了,直接回车。

接下来就不需要DBA再输入什么了,等着ORACLE给你生成报表吧。

Using the report name awrrpt_1_7331_7355.html

..................

.......................

End of Report

Report written to awrrpt_1_7331_7355.html

打开最终生成的统计报表,界面如下:

提示:

问:前面提示输入snaps时哪来的这么多snapshots啊?

答:这都是ORACLE偷偷摸摸一点一点(每小时一次)收集的啊!

问:它究竟收集了多久的啊?

答:从当前的记录看,至少有7天了!

问:究竟啥是snapshot啊?

答:接着往下看!

 

 

 

2.2  生成指定数据库实例的统计报表

这项统计报表一般是针对多实例数据库,前面使用的脚本是生成数据库级别的统计报表,对于多实例的数据库,有时候DBA可能希望看到某个实例的表现,那么本脚本就能派上用场了。其实操作与上非常类似(都比较简单,需要DBA敲的字符加一块也没几个),注意执行的脚本不同的哟。

SQL> @$ORACLE_HOME/rdbms/admin/awrrpti.sql

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: 

此处需指定生成的报表格式,有txt和html两种选择,默认情况下为html格式。

Type Specified:  html

Instances in this Workload Repository schema

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

   DB Id     Inst Num DB Name      Instance     Host

------------ -------- ------------ ------------ ------------

  948405229         2 JSSDB        jssdbn2      jssdbn2

* 948405229         1 JSSDB        jssdbn1      jssdbn1

Enter value for dbid:  948405229

Using 948405229 for database Id

Enter value for inst_num:  1

Using 1 for instance number

相比标准统计报表的生成,这里多了两个需指定的值,就是选择要生成报表的DBID以及实例的ID。

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

                                                        Snap

Instance     DB Name        Snap Id    Snap Started    Level

------------ ------------ --------- ------------------ -----

jssdbn1      JSSDB              235 22 Oct 2009 00:00      1

                                236 22 Oct 2009 01:00      1

                                237 22 Oct 2009 02:00      1

                                238 22 Oct 2009 03:00      1

                                239 22 Oct 2009 04:00      1

                                240 22 Oct 2009 05:00      1

                                241 22 Oct 2009 06:00      1

                                242 22 Oct 2009 07:00      1

                                243 22 Oct 2009 08:00      1

                                244 22 Oct 2009 09:00      1

                                245 22 Oct 2009 10:00      1

                                246 22 Oct 2009 11:00      1

                                247 22 Oct 2009 12:00      1

                                248 22 Oct 2009 13:00      1

                                249 22 Oct 2009 14:00      1

                                250 22 Oct 2009 15:00      1

                                251 22 Oct 2009 16:00      1

                                252 22 Oct 2009 17:00      1

                                253 22 Oct 2009 18:00      1

                                254 22 Oct 2009 19:00      1

                                255 22 Oct 2009 20:00      1

                                256 22 Oct 2009 21:00      1

                                257 22 Oct 2009 22:00      1

                                258 22 Oct 2009 23:00      1

                                259 23 Oct 2009 00:00      1

                                260 23 Oct 2009 01:00      1

                                261 23 Oct 2009 02:00      1

                                262 23 Oct 2009 03:00      1

                                263 23 Oct 2009 04:00      1

                                264 23 Oct 2009 05:00      1

                                265 23 Oct 2009 06:00      1

                                266 23 Oct 2009 07:00      1

                                267 23 Oct 2009 08:00      1

Specify the Begin and End Snapshot Ids

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

Enter value for begin_snap: 

.....................

......................

剩下的步骤就与标准统计报表的步骤完全相同,这里就不重复演示了。

 

 

 

2.3  生成指定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

                                                        Snap

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静静的矗立着:)

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后,短暂等待几秒钟,报告就生成了。

2.4  生成指定数据库实例中指定SQL语句的统计报表

本项统计报表主要针对多实例数据库,不过基本操作与上非常类似(都比较简单,需要DBA敲的字符加一块也没几个),具体操作如下:

SQL>  @$ORACLE_HOME/rdbms/admin/awrsqrpi.sql

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: 

Type Specified:  html

Instances in this Workload Repository schema

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

   DB Id     Inst Num DB Name      Instance     Host

------------ -------- ------------ ------------ ------------

  948405229         2 JSSDB        jssdbn2      jssdbn2

* 948405229         1 JSSDB        jssdbn1      jssdbn1

Enter value for dbid:  948405229

Using 948405229 for database Id

Enter value for inst_num:  1

Using 1 for instance number

指定DBID以及实例的ID序号。

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 7 days of Completed Snapshots

                                                        Snap

Instance     DB Name        Snap Id    Snap Started    Level

------------ ------------ --------- ------------------ -----

jssdbn1      JSSDB              235 22 Oct 2009 00:00      1

                                236 22 Oct 2009 01:00      1

                                237 22 Oct 2009 02:00      1

                                238 22 Oct 2009 03:00      1

                                239 22 Oct 2009 04:00      1

                                240 22 Oct 2009 05:00      1

                                241 22 Oct 2009 06:00      1

                                242 22 Oct 2009 07:00      1

                                243 22 Oct 2009 08:00      1

                                244 22 Oct 2009 09:00      1

                                245 22 Oct 2009 10:00      1

                                246 22 Oct 2009 11:00      1

                                247 22 Oct 2009 12:00      1

                                248 22 Oct 2009 13:00      1

                                249 22 Oct 2009 14:00      1

                                250 22 Oct 2009 15:00      1

                                251 22 Oct 2009 16:00      1

                                252 22 Oct 2009 17:00      1

                                253 22 Oct 2009 18:00      1

                                254 22 Oct 2009 19:00      1

                                255 22 Oct 2009 20:00      1

                                256 22 Oct 2009 21:00      1

                                257 22 Oct 2009 22:00      1

                                258 22 Oct 2009 23:00      1

                                259 23 Oct 2009 00:00      1

                                260 23 Oct 2009 01:00      1

                                261 23 Oct 2009 02:00      1

                                262 23 Oct 2009 03:00      1

                                263 23 Oct 2009 04:00      1

                                264 23 Oct 2009 05:00      1

                                265 23 Oct 2009 06:00      1

                                266 23 Oct 2009 07:00      1

                                267 23 Oct 2009 08:00      1

Specify the Begin and End Snapshot Ids

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

Enter value for begin_snap:  236

Begin Snapshot Id specified: 236

Enter value for end_snap:  260

End   Snapshot Id specified: 260

指定开始和结束的快照ID:

Specify the SQL Id

~~~~~~~~~~~~~~~~~~

Enter value for sql_id:  7tc5u8t3mmzgf

指定要分析的SQL_ID。

SQL ID specified:  7tc5u8t3mmzgf

Specify the Report Name

~~~~~~~~~~~~~~~~~~~~~~~

The default report file name is awrsqlrpt_1_236_260.html.  To use this name,

press <return> to continue, otherwise enter an alternative.

Enter value for report_name: 

Using the report name awrsqlrpt_1_236_260.html

<HTML><HEAD><TITLE>AWR SQL Report</TITLE>

..........................

..........................

AWR 自动生成分析报表。

 

 

 

2.5  生成不同时间段时的统计对比报表

在没有awr之前,如果希望对不同时间段时,数据库的整体影响进行对比,只能依靠DBA手工查询相关视图,并通过时间条件来获取差异(还有些统计已经无法对比),而在AWR中,直接就提供了,对不同时间段时,数据库的性能统计做差异对比的功能。

执行脚本如下:

SQL>  @$ORACLE_HOME/rdbms/admin/awrddrpt.sql

Current Instance

~~~~~~~~~~~~~~~~

   DB Id       DB Id    DB Name      Inst Num Inst Num Instance

----------- ----------- ------------ -------- -------- ------------

 3812548755  3812548755 TEST08              1        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

Database Id and Instance Number for the First Pair of Snapshots

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

Using 3812548755 for Database Id for the first pair of snapshots

Using          1 for Instance Number for the first pair of snapshots

注意,下面紧接着,是选择第一份报表的相关参数,包括快照的区间,以及开始和结束的快照ID:

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

                                                        Snap

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

                               7485 26 10 月 2009 11:00     1

                               7486 26 10 月 2009 12:00     1

                               7487 26 10 月 2009 13:00     1

                               7488 26 10 月 2009 14:00     1

                               7489 26 10 月 2009 15:00     1

Specify the First Pair of Begin and End Snapshot Ids

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

Enter value for begin_snap:  7459

First Begin Snapshot Id specified: 7459

Enter value for end_snap:  7462

First End   Snapshot Id specified: 7462

然后,是选择要对比的报表相关参数,包括快照的区间,以及开始和结束的快照ID:

Instances in this Workload Repository schema

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

   DB Id     Inst Num DB Name      Instance     Host

------------ -------- ------------ ------------ ------------

* 3812548755        1 TEST08       test08       yans1

Database Id and Instance Number for the Second Pair of Snapshots

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

Using 3812548755 for Database Id for the second pair of snapshots

Using          1 for Instance Number for the second pair of snapshots

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_days2:  2

Listing the last 2 days of Completed Snapshots

                                                        Snap

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

                               7485 26 10 月 2009 11:00     1

                               7486 26 10 月 2009 12:00     1

                               7487 26 10 月 2009 13:00     1

                               7488 26 10 月 2009 14:00     1

                               7489 26 10 月 2009 15:00     1

Specify the Second Pair of Begin and End Snapshot Ids

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

Enter value for begin_snap2:  7483

Second Begin Snapshot Id specified: 7483

Enter value for end_snap2:  7486

Second End   Snapshot Id specified: 7486

最后,为要生成的报表命令:

Specify the Report Name

~~~~~~~~~~~~~~~~~~~~~~~

The default report file name is awrdiff_1_7459_1_7483.html  To use this name,

press <return> to continue, otherwise enter an alternative.

Enter value for report_name: awr_diff_1_7459_1_7483.html

Using the report name awr_diff_1_7459_1_7483.html

<HTML><HEAD><TITLE>Workload Repository Compare Period Report</TITLE>

...............

...............

报表生成以后,在显示时将以并列的形式,直观的显示出两个不同时间段里,数据库各项参数的差异,摘要如图:

2.6  生成指定SQL语句的统计报表

前例的对比是在单实例环境下进行的,如果希望对多实例的数据库做对比,那就要使用$ORACLE_HOME/rdbms/admin/awrddrpi.sql脚本了。该脚本的操作基本与前例相同,这里不再演示,感兴趣的朋友不妨自行测试。

 

 

 

三、查看AWR视图

不管是EM也好,或是前面演示中使用的awr*.sql脚本也好,实质都是访问ORACLE中的部分相关视图来生成统计数据,因此如果DBA对自己的理解能力有足够的自信,也可以直接查询动态性能视图(或相关数据字典)的方式来获取自己想要的那部分性能数据。ORACLE将这部分性能统计数据保存在DBA_HIST开头的数据字典中,要查询当前实例所有能够访问的DBA_HIST字典,可以通过下列语句:

SQL>  select * from dict where table_name like ¨DBA_HIST%¨;

TABLE_NAME                     COMMENTS

------------------------------ --------------------------------------------------------------------------------

DBA_HIST_DATABASE_INSTANCE     Database Instance Information

DBA_HIST_SNAPSHOT              Snapshot Information

DBA_HIST_SNAP_ERROR            Snapshot Error Information

DBA_HIST_BASELINE              Baseline Metadata Information

DBA_HIST_WR_CONTROL            Workload Repository Control Information

DBA_HIST_DATAFILE              Names of Datafiles

DBA_HIST_FILESTATXS            Datafile Historical Statistics Information

DBA_HIST_TEMPFILE              Names of Temporary Datafiles

DBA_HIST_TEMPSTATXS            Temporary Datafile Historical Statistics Information

DBA_HIST_COMP_IOSTAT           I/O stats aggregated on component level

DBA_HIST_SQLSTAT               SQL Historical Statistics Information

DBA_HIST_SQLTEXT               SQL Text

......................

........................

ORACLE 数据库中以DBA_HIST命名的视图非常多,下面简单介绍几个,比如说:

  • V$ACTIVE_SESSION_HISTORY

该视图由ASH自动维护,以每秒一次的频率收集当前系统中活动session的信息。虽然说是记录SESSION的历史记录,不过该视图与V$SESSION还是有差异的。

SQL> desc v$active_session_history;

Name                      Type         Nullable Default Comments 

------------------------- ------------ -------- ------- -------- 

SAMPLE_ID                 NUMBER       Y                         

SAMPLE_TIME               TIMESTAMP(3) Y                         

SESSION_ID                NUMBER       Y                         

SESSION_SERIAL#           NUMBER       Y                         

USER_ID                   NUMBER       Y                         

SQL_ID                    VARCHAR2(13) Y                         

SQL_CHILD_NUMBER          NUMBER       Y                         

SQL_PLAN_HASH_VALUE       NUMBER       Y                         

FORCE_MATCHING_SIGNATURE  NUMBER       Y                         

SQL_OPCODE                NUMBER       Y                         

PLSQL_ENTRY_OBJECT_ID     NUMBER       Y                         

PLSQL_ENTRY_SUBPROGRAM_ID NUMBER       Y                         

PLSQL_OBJECT_ID           NUMBER       Y                         

PLSQL_SUBPROGRAM_ID       NUMBER       Y                         

SERVICE_HASH              NUMBER       Y                         

SESSION_TYPE              VARCHAR2(10) Y                         

SESSION_STATE             VARCHAR2(7)  Y                         

QC_SESSION_ID             NUMBER       Y                         

QC_INSTANCE_ID            NUMBER       Y                         

BLOCKING_SESSION          NUMBER       Y                         

BLOCKING_SESSION_STATUS   VARCHAR2(11) Y                         

BLOCKING_SESSION_SERIAL#  NUMBER       Y                         

EVENT                     VARCHAR2(64) Y                         

EVENT_ID                  NUMBER       Y                         

EVENT#                    NUMBER       Y                         

SEQ#                      NUMBER       Y                         

P1TEXT                    VARCHAR2(64) Y                         

P1                        NUMBER       Y                         

P2TEXT                    VARCHAR2(64) Y                         

P2                        NUMBER       Y                         

P3TEXT                    VARCHAR2(64) Y                         

P3                        NUMBER       Y                         

WAIT_CLASS                VARCHAR2(64) Y                         

WAIT_CLASS_ID             NUMBER       Y                         

WAIT_TIME                 NUMBER       Y                         

TIME_WAITED               NUMBER       Y                         

XID                       RAW(8)       Y                         

CURRENT_OBJ#              NUMBER       Y                         

CURRENT_FILE#             NUMBER       Y                         

CURRENT_BLOCK#            NUMBER       Y                         

PROGRAM                   VARCHAR2(48) Y                         

MODULE                    VARCHAR2(48) Y                         

ACTION                    VARCHAR2(32) Y                         

CLIENT_ID                 VARCHAR2(64) Y                         

   v$session 中与操作相关的列均被收集,除此之外还冗余了部分列,这是为了方便DBA查询V$ACTIVE_SESSION_HISTORY时能够快速获取到自己需要的数据。

  • DBA_HIST_ACTIVE_SESS_HISTORY

该视图与V$ACTIVE_SESSION_HISTORY的结构灰常灰常灰常的想像,功能也灰常灰常灰常的类似,都是记录活动session的操作记录,所不同点在于,V$ACTIVE_SESSION_HISTORY是ORACLE自动在内存中维护的,受制于其可用内存区限制,并非所有记录都能保存,而DBA_HIST_ACTIVE_SESS_HISTORY视图则是维护到磁盘中的。简单理解的话,就是说通常情况下,DBA_HIST_ACTIVE_SESS_HISTORY视图的数据量要比V$ACTIVE_SESSION_HISTORY的多。

提示:上述结构并不绝对,因为默认情况下DBA_HIST_ACTIVE_SESS_HISTORY字典的数据每10秒收集一次,而V$ACTIVE_SESSION_HISTORY中则是每秒一次,因此也有可能V$ACTIVE_SESSION_HISTORY中记录量更大。不过相对来说,DBA_HIST字典中保存的数据更长久。

  • DBA_HIST_DATABASE_INSTANCE

该视图用来显示数据库和实例的信息,比如DBID,实例名,数据库版本等等信息,生成报表中第一行表格,就是由该视图生成的。如图:

如果你去分析awrrpt.sql脚本的话,会发现其中有如下脚本,上述表格中显示的内容信息,正是来自于下列脚本:

select distinct

       (case when cd.dbid = wr.dbid and 

                  cd.name = wr.db_name and

                  ci.instance_number = wr.instance_number and

                  ci.instance_name   = wr.instance_name

             then ¨* ¨

             else ¨  ¨

        end) || wr.dbid   dbbid

     , wr.instance_number instt_num

     , wr.db_name         dbb_name

     , wr.instance_name   instt_name

     , wr.host_name       host

  from dba_hist_database_instance wr, v$database cd, v$instance ci;

  • DBA_HIST_SNAPSHOT

该视图用来记录当前数据库收集到的快照信息。相信朋友应该还记得之前使用脚本生成报表时,输入完快照区间后显示的一堆列表,没错,那正是DBA_HIST_SNAPSHOT记录的内容,该段功能对应的代码如下:

select to_char(s.startup_time,¨dd Mon "at" HH24:mi:ss¨)  instart_fmt

     , di.instance_name                                  inst_name

     , di.db_name                                        db_name

     , s.snap_id                                         snap_id

     , to_char(s.end_interval_time,¨dd Mon YYYY HH24:mi¨) snapdat

     , s.snap_level                                      lvl

  from dba_hist_snapshot s

     , dba_hist_database_instance di

 where s.dbid              = :dbid

   and di.dbid             = :dbid

   and s.instance_number   = :inst_num

   and di.instance_number  = :inst_num

   and di.dbid             = s.dbid

   and di.instance_number  = s.instance_number

   and di.startup_time     = s.startup_time

   and s.end_interval_time >= decode( &num_days

                                   , 0   , to_date(¨31-JAN-9999¨,¨DD-MON-YYYY¨)

                                   , 3.14, s.end_interval_time

                                   , to_date(:max_snap_time,¨dd/mm/yyyy¨) - (&num_days-1))

 order by db_name, instance_name, snap_id;

 

 

 

四、AWR的几个帮助

4.1 Snapshots( 快照)

前面操作报表生成时,snap这个关键字已经出现过黑多黑多次了,想必你对它充满了疑惑,这个东西是哪尬来的咋来的谁让它来的呢?事实上,Snap是Snapshot的简写,这正是AWR在自动性方面的体现,虽然你没有创建,但是AWR自动帮你创建了(当然也可以手动创建snapshot),并且是定时(每小时)创建,定期清除(保留最近7天)。

Snapshots 是一组某个时间点时历史数据的集合,这些数据就可被ADDM(Automatic Database Diagnostic Monitor)用来做性能对比。默认情况下,AWR能够自动以每小时一次的频率生成Snapshots性能数据,并保留7天,,如果需要的话,DBA可以通过DBMS_WORKLOAD_REPOSITORY过程手动创建、删除或修改snapshots。

提示:调用DBMS_WORKLOAD_REPOSITORY包需要拥有DBA权限。

4.1.1  手动创建Snapshots

手动创建Snapshots,通过DBMS_WORKLOAD_REPOSITORY.CREATE_SNAPSHOT过程,例如:

SQL> exec dbms_workload_repository.create_snapshot();

PL/SQL procedure successfully completed.

然后可以通过DBA_HIST_SNAPSHOT 视图查看刚刚创建的Snapshots信息。

4.1.2  手动删除Snapshots

删除Snapshots是使用DBMS_WORKLOAD_REPOSITORY包的另一个过程:DROP_SNAPSHOT_RANGE,该过程在执行时可以通过指定snap_id的范围的方式一次删除多个Snapshots,例如:

SQL> select count(0) from dba_hist_snapshot where snap_id between 7509 and 7518;

  COUNT(0)

----------

        10

SQL> begin

  2   dbms_workload_repository.drop_snapshot_range(

  3     low_snap_id => 7509,

  4     high_snap_id => 7518,

  5     dbid => 3812548755);

  6  end;

  7  /

PL/SQL procedure successfully completed.

SQL> select count(0) from dba_hist_snapshot where snap_id between 7509 and 7518;

  COUNT(0)

----------

         0

注意当snapshots被删除的话,与其关联的ASH记录也会级联删除。

4.1.3  修改Snapshots设置

通过MODIFY_SNAPSHOT_SETTINGS过程,DBA可以调整包括快照收集频率、快照保存时间、以及捕获的SQL数量三个方面的设置。分别对应MODIFY_SNAPSHOT_SETTINGS的三个参数:

  • Retention :设置快照保存的时间,单位是分钟。可设置的值最小为1天,最大为100年。设置该参数值为0的话,就表示永久保留收集的快照信息。
  • Interval :设置快照收集的频率,以分钟为单位。可设置的值最小为10分钟,最大为1年。如果设置该参数值为0,就表示禁用AWR特性。
  • Topnsql :指定收集的比较占用资源的SQL数量,可设置的值最小为30,最大不超过100000000。

查看当前快照收集的相关设置,可以通过DBA_HIST_WR_CONTROL视图查看,例如:

SQL> select * from dba_hist_wr_control;

 

      DBID SNAP_INTERVAL            RETENTION            TOPNSQL

---------- ------------------------ -------------------- ----------

3812548755 +00000 01:00:00.0        +00007 00:00:00.0    DEFAULT

又比如通过MODIFY_SNAPSHOT_SETTTINGS过程修改snap_intrval的设置:

SQL> exec dbms_workload_repository.modify_snapshot_settings(interval=>120);

PL/SQL procedure successfully completed.

SQL> select * from dba_hist_wr_control;

 

      DBID SNAP_INTERVAL            RETENTION            TOPNSQL

---------- ------------------------ -------------------- ----------

3812548755 +00000 02:00:00.0        +00007 00:00:00.0    DEFAULT

4.2 Baselines( 基线)

Baseline ,直译的话叫做基线,顾名思义的方式理解,就是用于比较的基本线。因为Baseline中包含指定时间点时的性能数据,因此就可以用来与其它时间点时的状态数据做对比,以分析性能问题。

创建Baseline时,Snapshots是做为其中的一个组成部分存在,因此一般来说当AWR自动维护快照时,如果定义过baseline,与baseline相关的快照不会被删除,即使是过期的快照,这样就相当于手动保留了一份统计数据的历史信息,DBA可以在适当的时间将其与现有的快照进行对比,以生成相关的统计报表。

用户可以通过DBMS_WORKLOAD_REPOSITORY包中的相关过程,手动的创建或删除Baseline。

4.2.1  创建Baseline

创建Baseline使用CREATE_BASELINE过程,执行该过程时分别指定开始和结果的snap_id,然后为该baseline定义一个名称即可,例如:

SQL> BEGIN

  2    DBMS_WORKLOAD_REPOSITORY.CREATE_BASELINE(start_snap_id => 7550,

  3                                             end_snap_id   => 7660,

  4                                             baseline_name => ¨am_baseline¨);

  5  END;

  6  /

PL/SQL procedure successfully completed.

SQL> select dbid,baseline_name,start_snap_id,end_snap_id from dba_hist_baseline;

      DBID BASELINE_NAME        START_SNAP_ID END_SNAP_ID

---------- -------------------- ------------- -----------

3812548755 am_baseline                   7550        7660

4.2.2  删除Baseline

删除Baseline使用DROP_BASELINE过程,删除时可以通过cascade参数选择是否将其关联的Snapshots级别进行删除,例如:

SQL> BEGIN

  2    DBMS_WORKLOAD_REPOSITORY.DROP_BASELINE(baseline_name => ¨am_baseline¨,

  3                                           cascade       => true);

  4  END;

  5  /

PL/SQL procedure successfully completed.

SQL> select * from dba_hist_baseline;

no rows selected

SQL> select * from dba_hist_snapshot where snap_id between 7550 and 7660;

no rows selected

如上例中所示,删除时指定了cascade参数值为true,对应的snap也被级联删除了。

 

 

 

五、生成ASH报表

V$ACTIVE_SESSION_HISTORY 视图浏览起来确实方便,不过对于新手朋友其易用性就打了折扣,而且直观性方面也不太好,幸好ORACLE也提供了相应的报表脚本,可以生成指定的时间段内ASH相关的报表。

ORACLE 提供了两个报表脚本,即可以用来生成数据库级的统计信息,也可以针对RAC架构中某个实例在某个时间段的状态生成统计,下面分别介绍。

1、生成指定时间段时的统计报表

生成数据库级ASH统计报表使用ashrpt.sql脚本,该文件保存在$ORACLE_HOME/rdbms/admin目录下,基本上操作与AWR脚本非常类似,例如:

SQL>  @$ORACLE_HOME/rdbms/admin/ashrpt.sql

Current Instance

~~~~~~~~~~~~~~~~

   DB Id    DB Name      Inst Num Instance

----------- ------------ -------- ------------

 3812548755 TEST08              1 test08

Specify the Report Type

~~~~~~~~~~~~~~~~~~~~~~~

Enter ¨html¨ for an HTML report, or ¨text¨ for plain text

Defaults to ¨html¨

Enter value for report_type:  html

这里让选择生成的报表类型,同样是有html和text两种,默认情况下为html类型。

选完类型后,接下来会显示数据库的一些基本信息,包括ASH收集到的信息的区间

Type Specified:  html

Instances in this Workload Repository schema

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

   DB Id     Inst Num DB Name      Instance     Host

------------ -------- ------------ ------------ ------------

* 3812548755        1 TEST08       test08       yans1

Defaults to current database

Using database id: 3812548755

Defaults to current instance

Using instance number: 1

ASH Samples in this Workload Repository schema

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

Oldest ASH sample available:  09-10 月-09 10:11:02  [  38853 mins in the past]

Latest ASH sample available:  05-11 月-09 09:43:09  [      0 mins in the past]

Specify the timeframe to generate the ASH report

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

Enter begin time for report:

--    Valid input formats:

--      To specify absolute begin time:

--        [MM/DD[/YY]] HH24:MI[:SS]

--        Examples: 02/23/03 14:30:15

--                  02/23 14:30:15

--                  14:30:15

--                  14:30

--      To specify relative begin time: (start with ¨-¨ sign)

--        -[HH24:]MI

--        Examples: -1:15  (SYSDATE - 1 Hr 15 Mins)

--                  -25    (SYSDATE - 25 Mins)

Defaults to -15 mins

Enter value for begin_time:  -10

输入报表分析的开始时间,这里即可以输入一个时间类型的字串,比如09/23/2009 14:30:15,也可以直接输入时间,甚至更简单的,输入一个负整数例如-10,表示当前时间前10分钟做为开始时间。

Report begin time specified: -10

Enter duration in minutes starting from begin time:

Defaults to SYSDATE - begin_time

Press Enter to analyze till current time

Enter value for duration:  8

然后要输入统计的时间段,注意哟,不是让输入结束时间,而是说在前面输入的开始时间的基础上,希望收集多长时间内的信息做统计,默认情况下为sysdate-begin_time,即从开始时间到当前时间,这里为了显的与众不同,我就随便敲了个8。

Report duration specified:   8

Using 05-11 月-09 09:33:44 as report begin time

Using 05-11 月-09 09:41:44 as report end time

........................

........................

Specify the Report Name

~~~~~~~~~~~~~~~~~~~~~~~

The default report file name is ashrpt_1_1105_0941.html.  To use this name,

press  to continue, otherwise enter an alternative.

Enter value for report_name: 

输入报表的名称,默认会根据前面输入的值来生成一个名称,比如这里默认生成的名称为ashrpt_1_1105_0941.html。

Using the report name ashrpt_1_1105_0941.html

Summary of All User Input

-------------------------

Format         : HTML

DB Id          : 3812548755

Inst num       : 1

Begin time     : 05-11 月-09 09:33:44

End time       : 05-11 月-09 09:41:44

Slot width     : Default

Report targets : 0

Report name    : ashrpt_1_1105_0941.html

报表成功生成,可以随时打开ashrpt_1_1105_0941.html浏览详细信息了。

2、生成指定数据库实例的指定时间段时的统计报表

对于RAC架构的数据库,有时候DBA可能会希望看到其中某个节点(或实例)的负载情况,这种情况下,可以使用ashwrpi.sql(附加的i应该是表示instance),例如:

SQL>  @$ORACLE_HOME/rdbms/admin/ashrpti.sql

Specify the Report Type

~~~~~~~~~~~~~~~~~~~~~~~

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

------------ -------- ------------ ------------ ------------

  948405229         2 JSSDB        jssdbn2      jssdbn2

* 948405229         1 JSSDB        jssdbn1      jssdbn1

Defaults to current database

Enter value for dbid:  948405229

这里多了两步,首先是要选择数据库的DBID,接下来是选择实例ID。

Using database id: 948405229

Defaults to current instance

Enter value for inst_num:  1

Using instance number: 1

ASH Samples in this Workload Repository schema

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

Oldest ASH sample available:  15-Oct-09 21:24:53   [  29499 mins in the past]

Latest ASH sample available:  05-Nov-09 09:00:56   [      3 mins in the past]

Specify the timeframe to generate the ASH report

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

Enter begin time for report:

--    Valid input formats:

--      To specify absolute begin time:

--        [MM/DD[/YY]] HH24:MI[:SS]

--        Examples: 02/23/03 14:30:15

--                  02/23 14:30:15

--                  14:30:15

--                  14:30

--      To specify relative begin time: (start with ¨-¨ sign)

--        -[HH24:]MI

--        Examples: -1:15  (SYSDATE - 1 Hr 15 Mins)

--                  -25    (SYSDATE - 25 Mins)

Defaults to -15 mins

Enter value for begin_time: 

输入开始的时间,后面的步骤与前面生成数据库级的操作完全相同,不再演示。

前面介绍的这种种特性以及脚本均是工具,工具永远都只是起辅助的作用,能不能用好,还是取决于使用工具的人,祝好运吧。

原创粉丝点击