5

可视化oracle性能图表之“平均活动会话”篇 -利来国际app

赵全文 2021-11-05
1604

库尔特·恩格莱特、约翰·贝雷斯涅维奇、塞西莉亚·格瓦西奥在最大化数据库性能:使用数据库时间进行性能调整“的ppt第17页中提到,平均活动会话 = 所有会话的平均活动总和 (即:数据库时间) / 经过的时间。原文ppt描述如下图所示:


正如您所看到的,average active sessions = db time / elapsed time. 有关该ppt的其它内容请查看这个自行脑补。虽然“平均活动会话”我们可以通过前面描述的公式计算出来,不过您可能会问,那什么是db timeelapsed time? 在的官方文档中是这样描述的,请读下面我引用的一段介绍:

time model statistics

time model statistics use time to identify quantitative effects about specific actions performed on the database, such as logon operations and parsing. the most important time model statistic is database time, or db time. this statistic represents the total time spent in database calls for foreground sessions and is an indicator of the total instance workload. db time is measured cumulatively from the time of instance startup and is calculated by aggregating the cpu and wait times of all foreground sessions not waiting on idle wait events (non-idle user sessions).

time model statistics are accessible from the v$sess_time_model and v$sys_time_model views.

翻译成中文的意思是:

时间模型统计

时间模型统计使用时间来确定对数据库执行的特定操作(如登录操作和解析)的定量影响。最重要的时间模型统计数据是数据库时间数据库时间。此统计信息表示前台会话的数据库调用所花费的总时间,是实例总工作负载的指标。db时间是从实例启动时开始累积测量的,通过聚合所有未等待空闲等待事件(非空闲用户会话)的前台会话的cpu和等待时间来计算。

可以从v$sess_time_modelv$sys_time_model视图中访问时间模型统计信息

现在您已经知道,数据库时间来源于时间模型统计。另外,也提到了中会收集时间模型统计信息,是这样描述的:

automatic workload repository

awr collects, processes, and maintains performance statistics for problem detection and self-tuning purposes. this gathered data is stored both in memory and in the database, and is displayed in both reports and views.

the statistics collected and processed by awr include:

  • object statistics that determine both access and usage statistics of database segments

  • time model statistics based on time usage for activities, displayed in the v$sys_time_model and v$sess_time_model views

  • some of the system and session statistics collected in the v$sysstat and v$sesstat views

  • sql statements that are producing the highest load on the system, based on criteria such as elapsed time and cpu time

  • active session history (ash) statistics, representing the history of recent sessions activity

翻译成中文是:

自动工作负载存储库

awr收集、处理和维护性能统计数据,以便进行问题检测和自我调整。收集的数据存储在内存和数据库中,并显示在报告和视图中。

awr收集和处理的统计数据包括:

  • 确定数据库段的访问和使用统计信息的对象统计信息
  • 基于活动时间使用情况的时间模型统计信息,显示在v$sys_time_modelv$sess_time_model视图中
  • v$sysstat和v$sesstat视图中收集的一些系统和会话统计信息
  • 根据运行时间和cpu时间等条件在系统上产生最高负载的sql语句
  • 活动会话历史记录(ash)统计信息,表示最近会话活动的历史记录

换句话说,我们可以通过awr报告来获取db time。是这样解释awr报告的:

an awr report shows data captured between two snapshots (or two points in time). awr reports are divided into multiple sections. the content of the report contains the workload profile of the system for the selected range of snapshots. the html report includes links that can be used to navigate quickly between sections.


this section describes how to generate awr reports and contains the following topics:



翻译成中文是:

awr报告显示两个快照(或两个时间点)之间捕获的数据。awr报告分为多个部分。报告内容包含所选快照范围内系统的工作负载配置文件。html报告包含可用于在节之间快速导航的链接。

本节介绍如何生成awr报告,并包含以下主题:

  • 用于生成awr报告的用户界面
  • 使用命令行界面生成awr报告

这里,我通过emcc用户界面收集awr报告的步骤,详见下面两张屏幕截图:



最终awr报告中显示的db timeelapsed time是:


所以,这个数据库的平均活动会话db time / elapsed time = 61.01 mins / 60.24 mins = 1.013。我们知道,oracle默认每隔一小时会自动生成一个快照,而且每个快照的结束时间是下一个快照的开始时间,所以这些快照的采集时间都是连续的,除非期间有数据库的实例重启过。如果我们每次都要通过收集awr报告来计算平均活动会话,这显然是不可取的,而且我们计算出的平均活动会话都是间隔一小时(连续两个快照)的时间,如果要计算更加细粒度的间隔时间(如:1分钟)的平均活动会话,那么awr报告不能满足这个需求了。

可喜的是,oracle从10g版本开始,提供了视图,它显示长持续时间(60秒)短持续时间(15秒)系统度量的最新时间间隔捕获的系统度量值;提供了视图,它显示数据库中可用的所有系统度量值,此视图同时显示长持续时间(60秒,1小时历史记录)和短持续时间(15秒,仅一个间隔)指标;提供了视图,它显示系统度量长持续时间组中所有度量值的统计摘要的历史记录。这些视图中的所有列名及其含义分别见下图所示:




我们通过查询视图v$sysmetric中的列名metric_namemetric_unit可以得知,有一个度量名为average active sessions和度量单元为active sessions

sql>
sql> set linesize 100
sql> column metric_name format a25
sql> column metric_unit format a15
sql>
sql> select distinct metric_name
sql>      , metric_unit
sql> from v$sysmetric
sql> where metric_name = 'average active sessions'
sql> ;
metric_name               metric_unit
------------------------- ---------------
average active sessions   active sessions

sql>

接下来,我们从下面的八个维度来查看数据库的平均活动会话(average active sessions,简称:aas)

维度目录列表

实时的平均活动会话

sql查询语句如下:

-- average active sessions in real time.
set linesize 200
set pagesize 200
column metric_name    format a25
column snap_date_time format a20
column aas            format 999,999.99
alter session set nls_date_format = 'yyyy-mm-dd hh24:mi:ss';
select to_char(end_time, 'yyyy-mm-dd hh24:mi:ss') snap_date_time  -- the group column
     , metric_name                                                -- the series column
     , round(value, 2) aas                                        -- the value column
from v$sysmetric_history
where metric_name = 'average active sessions'
and   group_id = 2                                                -- just retrieve the name with "system metrics long duration" in v$metricgroup
order by snap_date_time
;

查询结果为:

snap_date_time       metric_name                       aas
-------------------- ------------------------- -----------
2021-11-05 15:25:14  average active sessions          1.10
2021-11-05 15:26:13  average active sessions           .78
2021-11-05 15:27:14  average active sessions           .75
2021-11-05 15:28:14  average active sessions          1.21
2021-11-05 15:29:13  average active sessions          1.32
2021-11-05 15:30:14  average active sessions          2.53
2021-11-05 15:31:14  average active sessions          3.42
2021-11-05 15:32:14  average active sessions          2.63
2021-11-05 15:33:13  average active sessions          2.38
2021-11-05 15:34:14  average active sessions          2.97
2021-11-05 15:35:14  average active sessions          4.25
2021-11-05 15:36:14  average active sessions          1.51
2021-11-05 15:37:14  average active sessions          3.30
2021-11-05 15:38:14  average active sessions          3.40
2021-11-05 15:39:14  average active sessions          3.23
2021-11-05 15:40:14  average active sessions           .94
2021-11-05 15:41:14  average active sessions          1.33
2021-11-05 15:42:14  average active sessions          1.49
2021-11-05 15:43:14  average active sessions          1.42
2021-11-05 15:44:14  average active sessions          1.82
2021-11-05 15:45:14  average active sessions          2.47
2021-11-05 15:46:14  average active sessions          1.80
2021-11-05 15:47:14  average active sessions          1.71
2021-11-05 15:48:14  average active sessions          1.21
2021-11-05 15:49:14  average active sessions          2.07
2021-11-05 15:50:14  average active sessions          1.77
2021-11-05 15:51:14  average active sessions           .90
2021-11-05 15:52:14  average active sessions          1.88
2021-11-05 15:53:14  average active sessions          1.01
2021-11-05 15:54:14  average active sessions          2.14
2021-11-05 15:55:14  average active sessions          1.62
2021-11-05 15:56:14  average active sessions          1.83
2021-11-05 15:57:14  average active sessions          2.72
2021-11-05 15:58:15  average active sessions          2.40
2021-11-05 15:59:14  average active sessions          1.44
2021-11-05 16:00:14  average active sessions          1.17
2021-11-05 16:01:15  average active sessions          2.08
2021-11-05 16:02:14  average active sessions          1.01
2021-11-05 16:03:14  average active sessions          1.77
2021-11-05 16:04:14  average active sessions          2.05
2021-11-05 16:05:14  average active sessions          1.26
2021-11-05 16:06:15  average active sessions          1.63
2021-11-05 16:07:14  average active sessions          2.26
2021-11-05 16:08:14  average active sessions           .85
2021-11-05 16:09:14  average active sessions          1.43
2021-11-05 16:10:14  average active sessions          2.81
2021-11-05 16:11:15  average active sessions          2.99
2021-11-05 16:12:14  average active sessions          2.42
2021-11-05 16:13:14  average active sessions          1.45
2021-11-05 16:14:14  average active sessions          1.71
2021-11-05 16:15:14  average active sessions          1.36
2021-11-05 16:16:14  average active sessions          1.98
2021-11-05 16:17:14  average active sessions          1.18
2021-11-05 16:18:15  average active sessions          2.87
2021-11-05 16:19:15  average active sessions          2.77
2021-11-05 16:20:14  average active sessions          1.33
2021-11-05 16:21:14  average active sessions          2.66
2021-11-05 16:22:14  average active sessions           .78
2021-11-05 16:23:14  average active sessions          1.53
2021-11-05 16:24:14  average active sessions          1.28
2021-11-05 16:25:15  average active sessions           .78
61 rows selected.

有了上面的sql查询和数据,但是我们如何生成相应的可视化图表来直观地显示数据的变化趋势呢?幸运的是,(最新版本为21.2.1,从可以下载适用于各个平台的版本)给我们提供了非常方便的用户自定义报告,只需10个步骤,就可以快速地生成“实时的平均活动会话”的用户自定义报告,所有操作依次如下图:











最终效果图,是这样的。


如果您觉得前面的操作步骤有些繁琐,也可以直接从下载并保存到您的电脑,然后打开sql developer直接导入到用户自定义报告“average active sessions”文件夹当中(第1、2步创建文件夹必不可少)也是可以的。

[返回维度目录列表]

最近24小时的平均活动会话

sql查询语句如下:

-- average active sessions in last 24 hours.
set linesize 200
set pagesize 200
column metric_name    format a25
column snap_date_time format a20
column aas            format 999,999.99
alter session set nls_date_format = 'yyyy-mm-dd hh24:mi:ss';
select to_char(end_time, 'yyyy-mm-dd hh24:mi:ss') snap_date_time  -- the group column
     , metric_name                                                -- the series column
     , round(average, 2) aas                                      -- the value column
from dba_hist_sysmetric_summary
where metric_name = 'average active sessions'
and   end_time >= sysdate - 1
order by snap_date_time
;

查询结果为:

snap_date_time       metric_name                       aas
-------------------- ------------------------- -----------
2021-11-04 17:00:02  average active sessions          1.44
2021-11-04 18:00:03  average active sessions          1.24
2021-11-04 19:00:03  average active sessions           .66
2021-11-04 20:00:03  average active sessions           .66
2021-11-04 21:00:03  average active sessions          1.12
2021-11-04 22:00:05  average active sessions           .82
2021-11-04 23:00:05  average active sessions          1.46
2021-11-05 00:00:06  average active sessions           .59
2021-11-05 01:00:06  average active sessions           .36
2021-11-05 02:00:06  average active sessions           .27
2021-11-05 03:00:07  average active sessions           .25
2021-11-05 04:00:07  average active sessions           .59
2021-11-05 05:00:08  average active sessions           .36
2021-11-05 06:00:09  average active sessions           .28
2021-11-05 07:00:10  average active sessions           .34
2021-11-05 08:00:10  average active sessions           .61
2021-11-05 09:00:11  average active sessions           .99
2021-11-05 10:00:11  average active sessions          1.22
2021-11-05 11:00:11  average active sessions          1.12
2021-11-05 12:00:12  average active sessions           .99
2021-11-05 12:59:13  average active sessions          1.48
2021-11-05 14:00:13  average active sessions          1.00
2021-11-05 15:00:13  average active sessions          1.55
2021-11-05 16:00:14  average active sessions          1.76
24 rows selected.

同理,将保存到您的电脑,然后直接导入到sql developer的用户自定义报告的“average active sessions”文件夹当中。最终,生成的图表如下所示:

[返回维度目录列表]

最近7天的平均活动会话(按每小时间隔)

sql查询语句如下:

-- average active sessions in last 7 days (interval by each hour).
set linesize 200
set pagesize 200
column metric_name    format a25
column snap_date_time format a20
column aas            format 999,999.99
alter session set nls_date_format = 'yyyy-mm-dd hh24:mi:ss';
select to_char(end_time, 'yyyy-mm-dd hh24:mi:ss') snap_date_time  -- the group column
     , metric_name                                                -- the series column
     , round(average, 2) aas                                      -- the value column
from dba_hist_sysmetric_summary
where metric_name = 'average active sessions'
and   end_time >= sysdate - 6
order by snap_date_time
;

查询结果为:

snap_date_time       metric_name                       aas
-------------------- ------------------------- -----------
2021-10-30 16:59:56  average active sessions          1.07
2021-10-30 17:59:56  average active sessions          1.02
2021-10-30 18:59:57  average active sessions          1.40
2021-10-30 19:59:57  average active sessions          1.13
2021-10-30 20:59:58  average active sessions          1.06
2021-10-30 21:59:58  average active sessions          1.20
2021-10-30 22:59:59  average active sessions          1.03
2021-10-31 00:00:00  average active sessions           .55
2021-10-31 01:00:00  average active sessions           .35
2021-10-31 02:00:01  average active sessions           .26
2021-10-31 03:00:01  average active sessions           .22
2021-10-31 04:00:02  average active sessions           .49
2021-10-31 05:00:02  average active sessions           .22
2021-10-31 06:00:03  average active sessions           .23
2021-10-31 07:00:04  average active sessions           .28
2021-10-31 08:00:05  average active sessions           .39
2021-10-31 09:00:05  average active sessions           .46
2021-10-31 10:00:05  average active sessions          1.00
2021-10-31 11:00:06  average active sessions          1.19
2021-10-31 12:00:06  average active sessions           .72
2021-10-31 13:00:07  average active sessions           .91
2021-10-31 14:00:08  average active sessions           .71
2021-10-31 15:00:08  average active sessions           .61
2021-10-31 16:00:08  average active sessions           .91
2021-10-31 17:00:09  average active sessions           .52
2021-10-31 17:59:09  average active sessions           .63
2021-10-31 19:00:10  average active sessions           .89
2021-10-31 20:00:10  average active sessions           .55
2021-10-31 21:00:12  average active sessions          1.13
2021-10-31 22:00:11  average active sessions           .90
2021-10-31 22:59:12  average active sessions           .74
2021-11-01 00:00:12  average active sessions           .51
2021-11-01 01:00:13  average active sessions           .32
2021-11-01 02:00:14  average active sessions           .25
2021-11-01 03:00:14  average active sessions           .22
2021-11-01 04:00:15  average active sessions           .59
2021-11-01 04:59:16  average active sessions           .21
2021-11-01 06:00:16  average active sessions           .21
2021-11-01 07:00:17  average active sessions           .23
2021-11-01 08:00:17  average active sessions           .51
2021-11-01 09:00:18  average active sessions          1.24
2021-11-01 09:59:18  average active sessions          1.93
2021-11-01 11:00:19  average active sessions          1.98
2021-11-01 12:00:19  average active sessions          1.58
2021-11-01 13:00:20  average active sessions           .91
2021-11-01 14:00:20  average active sessions           .66
2021-11-01 14:59:21  average active sessions          1.19
2021-11-01 16:00:22  average active sessions          1.45
2021-11-01 17:00:22  average active sessions          1.26
2021-11-01 18:00:23  average active sessions           .69
2021-11-01 18:59:24  average active sessions           .57
2021-11-01 20:00:24  average active sessions           .92
2021-11-01 21:00:24  average active sessions           .70
2021-11-01 22:00:24  average active sessions           .58
2021-11-01 22:59:26  average active sessions           .83
2021-11-01 23:59:26  average active sessions           .56
2021-11-02 00:59:27  average active sessions           .28
2021-11-02 02:00:27  average active sessions           .23
2021-11-02 03:00:27  average active sessions           .20
2021-11-02 04:00:28  average active sessions           .53
2021-11-02 04:59:29  average active sessions           .22
2021-11-02 05:59:29  average active sessions           .20
2021-11-02 06:59:30  average active sessions           .22
2021-11-02 08:00:30  average active sessions           .30
2021-11-02 09:00:31  average active sessions           .68
2021-11-02 10:00:31  average active sessions           .83
2021-11-02 10:59:32  average active sessions           .96
2021-11-02 11:59:33  average active sessions           .84
2021-11-02 13:00:33  average active sessions           .53
2021-11-02 14:00:34  average active sessions           .54
2021-11-02 14:59:35  average active sessions           .66
2021-11-02 15:59:34  average active sessions          1.16
2021-11-02 17:00:35  average active sessions           .91
2021-11-02 18:00:36  average active sessions          1.05
2021-11-02 18:59:36  average active sessions           .57
2021-11-02 19:59:37  average active sessions           .53
2021-11-02 20:59:38  average active sessions           .66
2021-11-02 22:00:38  average active sessions           .83
2021-11-02 23:00:39  average active sessions          1.28
2021-11-02 23:59:39  average active sessions           .31
2021-11-03 00:59:40  average active sessions           .25
2021-11-03 01:59:40  average active sessions           .23
2021-11-03 02:59:41  average active sessions           .21
2021-11-03 04:00:41  average active sessions           .68
2021-11-03 05:00:42  average active sessions           .21
2021-11-03 05:59:42  average active sessions           .20
2021-11-03 06:59:43  average active sessions           .22
2021-11-03 07:59:43  average active sessions           .29
2021-11-03 08:59:44  average active sessions           .68
2021-11-03 10:00:45  average active sessions           .98
2021-11-03 10:59:46  average active sessions          1.62
2021-11-03 11:59:46  average active sessions          1.00
2021-11-03 12:59:46  average active sessions           .93
2021-11-03 13:59:47  average active sessions           .55
2021-11-03 14:59:47  average active sessions           .74
2021-11-03 15:59:48  average active sessions          1.05
2021-11-03 16:59:48  average active sessions           .95
2021-11-03 17:59:49  average active sessions           .96
2021-11-03 19:00:50  average active sessions           .74
2021-11-03 19:59:50  average active sessions           .51
2021-11-03 20:59:51  average active sessions           .56
2021-11-03 21:59:52  average active sessions           .59
2021-11-03 22:59:52  average active sessions           .50
2021-11-04 00:00:53  average active sessions           .37
2021-11-04 00:59:53  average active sessions           .28
2021-11-04 01:59:53  average active sessions           .23
2021-11-04 02:59:54  average active sessions           .21
2021-11-04 03:59:54  average active sessions           .45
2021-11-04 04:59:55  average active sessions           .24
2021-11-04 05:59:55  average active sessions           .21
2021-11-04 06:59:56  average active sessions           .25
2021-11-04 07:59:56  average active sessions           .30
2021-11-04 08:59:57  average active sessions           .71
2021-11-04 09:59:58  average active sessions          1.47
2021-11-04 10:59:59  average active sessions          1.28
2021-11-04 11:59:59  average active sessions          1.15
2021-11-04 13:00:00  average active sessions           .71
2021-11-04 14:00:00  average active sessions           .75
2021-11-04 15:00:01  average active sessions          1.14
2021-11-04 16:00:01  average active sessions          1.78
2021-11-04 17:00:02  average active sessions          1.44
2021-11-04 18:00:03  average active sessions          1.24
2021-11-04 19:00:03  average active sessions           .66
2021-11-04 20:00:03  average active sessions           .66
2021-11-04 21:00:03  average active sessions          1.12
2021-11-04 22:00:05  average active sessions           .82
2021-11-04 23:00:05  average active sessions          1.46
2021-11-05 00:00:06  average active sessions           .59
2021-11-05 01:00:06  average active sessions           .36
2021-11-05 02:00:06  average active sessions           .27
2021-11-05 03:00:07  average active sessions           .25
2021-11-05 04:00:07  average active sessions           .59
2021-11-05 05:00:08  average active sessions           .36
2021-11-05 06:00:09  average active sessions           .28
2021-11-05 07:00:10  average active sessions           .34
2021-11-05 08:00:10  average active sessions           .61
2021-11-05 09:00:11  average active sessions           .99
2021-11-05 10:00:11  average active sessions          1.22
2021-11-05 11:00:11  average active sessions          1.12
2021-11-05 12:00:12  average active sessions           .99
2021-11-05 12:59:13  average active sessions          1.48
2021-11-05 14:00:13  average active sessions          1.00
2021-11-05 15:00:13  average active sessions          1.55
2021-11-05 16:00:14  average active sessions          1.76
144 rows selected.

同理,保存到您的sql developer的自定义报告当中。最后,生成的图表为:

[返回维度目录列表]

最近7天的平均活动会话(按每天间隔)

sql查询语句如下:

-- average active sessions in last 7 days (interval by each day).
set linesize 200
set pagesize 200
column metric_name format a25
column snap_date   format a12
column aas         format 999,999.99
alter session set nls_date_format = 'yyyy-mm-dd hh24:mi:ss';
with aas_per_hour as (
select to_char(end_time, 'yyyy-mm-dd') snap_date
     , metric_name
     , average
from dba_hist_sysmetric_summary
where metric_name = 'average active sessions'
and   end_time >= sysdate - 6
)
select snap_date                                    -- the group column
     , metric_name                                  -- the series column
     , round(sum(average)/count(snap_date), 2) aas  -- the value column
from aas_per_hour
group by snap_date
       , metric_name
order by snap_date
;

查询结果为:

snap_date    metric_name                       aas
------------ ------------------------- -----------
2021-10-30   average active sessions          1.13
2021-10-31   average active sessions           .62
2021-11-01   average active sessions           .80
2021-11-02   average active sessions           .61
2021-11-03   average active sessions           .64
2021-11-04   average active sessions           .79
2021-11-05   average active sessions           .81
7 rows selected.

同理,保存并导入您的sql developer当中。最终的图表效果如下所示:

[返回维度目录列表]

最近31天的平均活动会话(按每小时间隔)

sql查询语句如下:

-- average active sessions in last 31 days (interval by each hour).
set linesize 200
set pagesize 200
column metric_name    format a25
column snap_date_time format a20
column aas            format 999,999.99
alter session set nls_date_format = 'yyyy-mm-dd hh24:mi:ss';
select to_char(end_time, 'yyyy-mm-dd hh24:mi:ss') snap_date_time  -- the group column
     , metric_name                                                -- the series column
     , round(average, 2) aas                                      -- the value column
from dba_hist_sysmetric_summary
where metric_name = 'average active sessions'
and   end_time >= sysdate - 30
order by snap_date_time
;

查询结果为:

snap_date_time       metric_name                       aas
-------------------- ------------------------- -----------
......               ......                           ....
2021-10-31 08:00:05  average active sessions           .39
2021-10-31 09:00:05  average active sessions           .46
2021-10-31 10:00:05  average active sessions          1.00
2021-10-31 11:00:06  average active sessions          1.19
2021-10-31 12:00:06  average active sessions           .72
2021-10-31 13:00:07  average active sessions           .91
2021-10-31 14:00:08  average active sessions           .71
2021-10-31 15:00:08  average active sessions           .61
2021-10-31 16:00:08  average active sessions           .91
2021-10-31 17:00:09  average active sessions           .52
2021-10-31 17:59:09  average active sessions           .63
2021-10-31 19:00:10  average active sessions           .89
2021-10-31 20:00:10  average active sessions           .55
2021-10-31 21:00:12  average active sessions          1.13
2021-10-31 22:00:11  average active sessions           .90
2021-10-31 22:59:12  average active sessions           .74
2021-11-01 00:00:12  average active sessions           .51
2021-11-01 01:00:13  average active sessions           .32
2021-11-01 02:00:14  average active sessions           .25
2021-11-01 03:00:14  average active sessions           .22
2021-11-01 04:00:15  average active sessions           .59
2021-11-01 04:59:16  average active sessions           .21
2021-11-01 06:00:16  average active sessions           .21
2021-11-01 07:00:17  average active sessions           .23
2021-11-01 08:00:17  average active sessions           .51
2021-11-01 09:00:18  average active sessions          1.24
2021-11-01 09:59:18  average active sessions          1.93
2021-11-01 11:00:19  average active sessions          1.98
2021-11-01 12:00:19  average active sessions          1.58
2021-11-01 13:00:20  average active sessions           .91
2021-11-01 14:00:20  average active sessions           .66
2021-11-01 14:59:21  average active sessions          1.19
2021-11-01 16:00:22  average active sessions          1.45
2021-11-01 17:00:22  average active sessions          1.26
2021-11-01 18:00:23  average active sessions           .69
2021-11-01 18:59:24  average active sessions           .57
2021-11-01 20:00:24  average active sessions           .92
2021-11-01 21:00:24  average active sessions           .70
2021-11-01 22:00:24  average active sessions           .58
2021-11-01 22:59:26  average active sessions           .83
2021-11-01 23:59:26  average active sessions           .56
2021-11-02 00:59:27  average active sessions           .28
2021-11-02 02:00:27  average active sessions           .23
2021-11-02 03:00:27  average active sessions           .20
2021-11-02 04:00:28  average active sessions           .53
2021-11-02 04:59:29  average active sessions           .22
2021-11-02 05:59:29  average active sessions           .20
2021-11-02 06:59:30  average active sessions           .22
2021-11-02 08:00:30  average active sessions           .30
2021-11-02 09:00:31  average active sessions           .68
2021-11-02 10:00:31  average active sessions           .83
2021-11-02 10:59:32  average active sessions           .96
2021-11-02 11:59:33  average active sessions           .84
2021-11-02 13:00:33  average active sessions           .53
2021-11-02 14:00:34  average active sessions           .54
2021-11-02 14:59:35  average active sessions           .66
2021-11-02 15:59:34  average active sessions          1.16
2021-11-02 17:00:35  average active sessions           .91
2021-11-02 18:00:36  average active sessions          1.05
2021-11-02 18:59:36  average active sessions           .57
2021-11-02 19:59:37  average active sessions           .53
2021-11-02 20:59:38  average active sessions           .66
2021-11-02 22:00:38  average active sessions           .83
2021-11-02 23:00:39  average active sessions          1.28
2021-11-02 23:59:39  average active sessions           .31
2021-11-03 00:59:40  average active sessions           .25
2021-11-03 01:59:40  average active sessions           .23
2021-11-03 02:59:41  average active sessions           .21
2021-11-03 04:00:41  average active sessions           .68
2021-11-03 05:00:42  average active sessions           .21
2021-11-03 05:59:42  average active sessions           .20
2021-11-03 06:59:43  average active sessions           .22
2021-11-03 07:59:43  average active sessions           .29
2021-11-03 08:59:44  average active sessions           .68
2021-11-03 10:00:45  average active sessions           .98
2021-11-03 10:59:46  average active sessions          1.62
2021-11-03 11:59:46  average active sessions          1.00
2021-11-03 12:59:46  average active sessions           .93
2021-11-03 13:59:47  average active sessions           .55
2021-11-03 14:59:47  average active sessions           .74
2021-11-03 15:59:48  average active sessions          1.05
2021-11-03 16:59:48  average active sessions           .95
2021-11-03 17:59:49  average active sessions           .96
2021-11-03 19:00:50  average active sessions           .74
2021-11-03 19:59:50  average active sessions           .51
2021-11-03 20:59:51  average active sessions           .56
2021-11-03 21:59:52  average active sessions           .59
2021-11-03 22:59:52  average active sessions           .50
2021-11-04 00:00:53  average active sessions           .37
2021-11-04 00:59:53  average active sessions           .28
2021-11-04 01:59:53  average active sessions           .23
2021-11-04 02:59:54  average active sessions           .21
2021-11-04 03:59:54  average active sessions           .45
2021-11-04 04:59:55  average active sessions           .24
2021-11-04 05:59:55  average active sessions           .21
2021-11-04 06:59:56  average active sessions           .25
2021-11-04 07:59:56  average active sessions           .30
2021-11-04 08:59:57  average active sessions           .71
2021-11-04 09:59:58  average active sessions          1.47
2021-11-04 10:59:59  average active sessions          1.28
2021-11-04 11:59:59  average active sessions          1.15
2021-11-04 13:00:00  average active sessions           .71
2021-11-04 14:00:00  average active sessions           .75
2021-11-04 15:00:01  average active sessions          1.14
2021-11-04 16:00:01  average active sessions          1.78
2021-11-04 17:00:02  average active sessions          1.44
2021-11-04 18:00:03  average active sessions          1.24
2021-11-04 19:00:03  average active sessions           .66
2021-11-04 20:00:03  average active sessions           .66
2021-11-04 21:00:03  average active sessions          1.12
2021-11-04 22:00:05  average active sessions           .82
2021-11-04 23:00:05  average active sessions          1.46
2021-11-05 00:00:06  average active sessions           .59
2021-11-05 01:00:06  average active sessions           .36
2021-11-05 02:00:06  average active sessions           .27
2021-11-05 03:00:07  average active sessions           .25
2021-11-05 04:00:07  average active sessions           .59
2021-11-05 05:00:08  average active sessions           .36
2021-11-05 06:00:09  average active sessions           .28
2021-11-05 07:00:10  average active sessions           .34
2021-11-05 08:00:10  average active sessions           .61
2021-11-05 09:00:11  average active sessions           .99
2021-11-05 10:00:11  average active sessions          1.22
2021-11-05 11:00:11  average active sessions          1.12
2021-11-05 12:00:12  average active sessions           .99
2021-11-05 12:59:13  average active sessions          1.48
2021-11-05 14:00:13  average active sessions          1.00
2021-11-05 15:00:13  average active sessions          1.55
2021-11-05 16:00:14  average active sessions          1.76
720 rows selected.

然后,将导入您的sql developer。最终,生成的图表为:

[返回维度目录列表]

最近31天的平均活动会话(按每天间隔)

sql查询语句如下:

-- average active sessions in last 31 days (interval by each day).
set linesize 200
set pagesize 200
column metric_name format a25
column snap_date   format a12
column aas         format 999,999.99
alter session set nls_date_format = 'yyyy-mm-dd hh24:mi:ss';
with aas_per_hour as (
select to_char(end_time, 'yyyy-mm-dd') snap_date
     , metric_name
     , average
from dba_hist_sysmetric_summary
where metric_name = 'average active sessions'
and   end_time >= sysdate - 30
)
select snap_date                                    -- the group column
     , metric_name                                  -- the series column
     , round(sum(average)/count(snap_date), 2) aas  -- the value column
from aas_per_hour
group by snap_date
       , metric_name
order by snap_date
;

查询结果为:

snap_date    metric_name                       aas
------------ ------------------------- -----------
2021-10-06   average active sessions           .49
2021-10-07   average active sessions           .59
2021-10-08   average active sessions          1.08
2021-10-09   average active sessions          1.35
2021-10-10   average active sessions          1.12
2021-10-11   average active sessions          1.97
2021-10-12   average active sessions          1.92
2021-10-13   average active sessions          1.99
2021-10-14   average active sessions          1.89
2021-10-15   average active sessions          2.44
2021-10-16   average active sessions          1.53
2021-10-17   average active sessions          1.58
2021-10-18   average active sessions          2.77
2021-10-19   average active sessions          2.83
2021-10-20   average active sessions          3.05
2021-10-21   average active sessions          2.05
2021-10-22   average active sessions          1.99
2021-10-23   average active sessions          1.41
2021-10-24   average active sessions          1.57
2021-10-25   average active sessions          2.41
2021-10-26   average active sessions          1.68
2021-10-27   average active sessions          1.30
2021-10-28   average active sessions          1.51
2021-10-29   average active sessions          1.27
2021-10-30   average active sessions           .90
2021-10-31   average active sessions           .62
2021-11-01   average active sessions           .80
2021-11-02   average active sessions           .61
2021-11-03   average active sessions           .64
2021-11-04   average active sessions           .79
2021-11-05   average active sessions           .81
31 rows selected.

然后,将导入sql developer。最终的图表是这样的:

[返回维度目录列表]

自定义时间段的平均活动会话(按每小时间隔)

sql查询语句如下:

-- average active sessions custom time period (interval by each hour).
set linesize 200
set pagesize 200
column metric_name    format a25
column snap_date_time format a20
column aas            format 999,999.99
alter session set nls_date_format = 'yyyy-mm-dd hh24:mi:ss';
select to_char(end_time, 'yyyy-mm-dd hh24:mi:ss') snap_date_time  -- the group column
     , metric_name                                                -- the series column
     , round(average, 2) aas                                      -- the value column
from dba_hist_sysmetric_summary
where metric_name = 'average active sessions'
and   (end_time between to_date(:start_date, 'yyyy-mm-dd hh24:mi:ss')
                and     to_date(:end_date, 'yyyy-mm-dd hh24:mi:ss')
      )
order by snap_date_time
;

由于上面“自定义时间段”的sql语句中使用了绑定变量,所以在sql*plus中执行会报错,这里不再显示查询结果。同时将导入sql developer。这里切记,在运行图表时,首先需要输入两个绑定变量“开始时间”和“结束时间”的值,然后才能生成相应的图表,两个步骤分别如下所示:


[返回维度目录列表]

自定义时间段的平均活动会话(按每天间隔)

sql查询语句如下:

-- average active sessions custom time period (interval by each day).
set linesize 200
set pagesize 200
column metric_name format a25
column snap_date   format a12
column aas         format 999,999.99
alter session set nls_date_format = 'yyyy-mm-dd hh24:mi:ss';
with aas_per_hour as (
select to_char(end_time, 'yyyy-mm-dd') snap_date
     , metric_name
     , average
from dba_hist_sysmetric_summary
where metric_name = 'average active sessions'
and   (end_time between to_date(:start_date, 'yyyy-mm-dd')
                and     to_date(:end_date, 'yyyy-mm-dd')
      )
)
select snap_date                                    -- the group column
     , metric_name                                  -- the series column
     , round(sum(average)/count(snap_date), 2) aas  -- the value column
from aas_per_hour
group by snap_date
       , metric_name
order by snap_date
;

同理,不再显示上面sql语句的查询结果。然后将导入sql developer。和前面的图表一样,两个操作步骤分别为:



[返回维度目录列表]

可视化oracle性能图表之“平均活动会话”篇,今天就分享到这里结束了。下一篇我将在“平均活动会话”图表的基础上再增加一个“逻辑cpu数目”,相信那样的图表显示效果会更加形象和美观更容易观察到目前数据库是否存在性能瓶颈,小伙伴们不要走开哟,敬请期待!!!

参考文章:




更新于2021年11月6日下午:

  • 因为我的数据库中awr报告的保留时间是一个月31天,如果您的数据库的awr报告没有那么长的保留时间,两个维度中的“最近31天的平均活动会话(...)/(...)”会和我的图表有所差距;
  • 将最后段落中的“美观”二字划上“删除线”标记,并增加内容“更容易观察到目前数据库是否存在性能瓶颈”
  • 个维度的无序列表增加html的锚点功能,单击每一个无序列表项都能自动跳转到文章相应的段落标题处;
  • 增加“参考文章”列表;
最后修改时间:2021-11-06 16:29:34
「喜欢文章,快来给作者赞赏墨值吧」
3人已赞赏
【利来手机国际的版权声明】本文为墨天轮用户原创内容,转载时必须标注文章的来源(墨天轮),文章链接,文章作者等基本信息,否则作者和墨天轮有权追究责任。如果您发现墨天轮中有涉嫌抄袭或者侵权的内容,欢迎发送邮件至:[email protected]进行举报,并提供相关证据,一经查实,墨天轮将立刻删除相关内容。

评论