---
title: "生成 ASH 报告 - OceanBase 数据库 V4.2.5 | OceanBase 文档中心"
description: "生成 ASH 报告 您可以通过调用 ASH PL 包生成对应的 ASH 报告。 SQL 语法 ASH PL 包的信息有如下几个字段组成： MySQL 模式 Oracle 模式 obclient [oceanbase]&gt; call dbms_workload_repository.ash_report( &#x27;BTIME&#x27;…"
---
切换语言

- 中文站 - 简体中文
- International - English
- 日本站 - 日本語

文档反馈![](https://mdn.alipayobjects.com/huamei_22khvb/afts/img/A*P8CuR4UJ_FkAAAAAAAAAAAAADiGDAQ/original) OceanBase 数据库分布式版 - V 4.2.5 LTS

# 生成 ASH 报告

更新时间：2026-04-15 17:16:59

[编辑](https://github.com/oceanbase/oceanbase-doc/edit/V4.2.5/zh-CN/700.reference/1000.performance-tuning-guide/400.performance-diagnosis/500.ash-report-diagnosis/200.generate-ash-report.md)  

您可以通过调用 ASH PL 包生成对应的 ASH 报告。

## SQL 语法

ASH PL 包的信息有如下几个字段组成：

    MySQL 模式   Oracle 模式

```sql
obclient [oceanbase]> call dbms_workload_repository.ash_report(
  'BTIME',
  'ETIME',
  'SQL_ID',
  'TRACE_ID',
  'WAIT_CLASS',
  'REPORT_TYPE',
  'SVR_IP',
  'SVR_PORT',
  'TENANT_ID');

```

```sql
obclient [SYS]> call dbms_workload_repository.ash_report(
  BTIME => 'xxxx',
  ETIME => 'xxxx',  
  SQL_ID => 'xxxx',
  TRACE_ID => 'xxxx',
  WAIT_CLASS => 'xxxx',
  REPORT_TYPE => 'xxxx',
  SVR_IP => 'xxxx',
  SVR_PORT=> 'xxxx',
  TENANT_ID => 'xxxx');

```

参数说明如下：

| **参数** | **说明** |
| --- | --- |
| BTIME | 采样开始时间，必填。 |
| ETIME | 采样结束时间，必填。 |
| SQL_ID | 待采样 SQL 的 `SQL_ID`，不填或填 `NULL` 则表示不限制 `SQL_ID`。 |
| TRACE_ID | 待采样 SQL 的 `TRACE_ID`，不填或填 `NULL` 则表示不限制 `TRACE_ID`。 |
| WAIT_CLASS | 待采样的事件类型。`WAIT_CLASS` 取值参考 `GV$OB_ACTIVE_SESSION_HISTORY.WAIT_CLASS` 字段的取值，不填或填 `NULL` 则表示不限制等待类型。 |
| REPORT_TYPE | 报告类型，目前支持 `HTML` 和 `TEXT` 类型，不填或填 `NULL` 则表示默认为 `TEXT` 类型。 |
| SVR_IP | 用于指定生成 ASH Report 的节点 IP，不填或填 `NULL` 则表示不限制 `SVR_IP`。 |
| SVR_PORT | 用于指定生成 ASH Report 的节点端口，不填或填 `NULL` 则表示不限制 `SVR_PORT`。 |
| TENANT_ID | 用于指定生成 ASH Report 的租户 ID，不填或填 `NULL` 则表示不限制 `TENANT_ID`。 |

#### 注意

- 在不同租户下，不限制 SVR_IP、SVR_PORT、TENANT_ID 时的行为如下：
     - 对于 sys 租户，采集所有 IP、端口和租户的信息。
     - 对于用户租户，采集该租户下的所有 IP 和端口信息。
 - 在 MySQL 模式下，如果非必填字段中的某个字段被显式设置为某个值，则其余非必填字段必须显式设为 NULL，而不能忽略不填写。

该包中相关信息可通过查询 `GV$OB_ACTIVE_SESSION_HISTORY` 视图获取。`GV$OB_ACTIVE_SESSION_HISTORY` 视图提供了会话活动信息。任何一个连接到数据库且排队等待的会话都会被考虑是一个活动的会话，每个会话采样都是通过 `GV$OB_ACTIVE_SESSION_HISTORY` 视图返回的一组行数据，在会话采样期间的每个会话会在视图中被显示。有关该视图的详细信息，参见 [GV$OB_ACTIVE_SESSION_HISTORY（MySQL 模式）](https://www.oceanbase.com/docs/common-oceanbase-database-cn-1000000001501537) 和 [GV$OB_ACTIVE_SESSION_HISTORY（Oracle 模式）](https://www.oceanbase.com/docs/common-oceanbase-database-cn-1000000001500664)。

## 操作步骤

生成 ASH 报告的步骤如下。

1. 使用租户管理员登录集群的 MySQL 租户，进入 OceanBase 数据库。

   ```shell
   $ obclient -h172.xx.xxx.xxx -Pxxxx -uroot@mysql -pxxxx -A

   ```
 2. 在控制台界面展示报告信息。

   调用 ASH PL 包，输入需要诊断的开始时间、结束时间以及结束后以何种类型展示报告。

   #### 说明

   控制台界面查看报告内容时建议类型设置为 TEXT。

      - 在界面上以 TEXT 的类型展示报告内容。

       设置诊断开始时间为 `2024-02-22 19:26:47`，诊断结束时间为 `2024-06-22 19:27:07`，报告展示类型为 `TEXT`，其他字段值根据是否需要来设置。

       ```shell
       obclient [test]> CALL DBMS_WORKLOAD_REPOSITORY.ASH_REPORT(  '2023-09-22 10:26:47',  '2024-06-22 20:27:07', NULL, NULL, NULL, 'TEXT', NULL, NULL, NULL);

       ```

       截取生成的部分内容：

       ```shell
         ASH Report

                 Cluster Name: test424
             Observer Version: OceanBase 4.2.4.0 (200000342024061210-c4c0c18741e45a1d40889b6147c3132574xxxxxx)
         Operation System Info: Linux(3.10.0-327.ali2019.alios7.x86_64)_x86_64
         User Input Begin Time: 2023-09-22 10:26:47
             User Input End Time: 2024-06-22 20:27:07
             Analysis Begin Time: 2024-06-13 18:24:34
             Analysis End Time: 2024-06-14 16:42:55
                 Elapsed Time: 80300
                 Num of Sample: 16433
         Average Active Sessions: 0.20

         Top Active Tenants:
         - this section lists top active tenant information
         - Total Count: num of records during ash report analysis time period
         - Wait Event Count: num of records when session is on wait event
         - On CPU Count: num of records when session is on cpu
         - Avg Active Sessions: average active sessions during ash report analysis time period
         - % Activity: activity(cpu + wait) percentage for given tenant
         +---------+------------+------------------+-----------------------+-------------------+--------------------+-----------+
         |Tenant ID|Session Type|       Total Count|       Wait Event Count|       On CPU Count| Avg Active Sessions| % Activity|
         +---------+------------+------------------+-----------------------+-------------------+--------------------+-----------+
         |     1002|  BACKGROUND|             16401|                   1951|              14450|                0.20|     99.81%|
         |     1002|  FOREGROUND|                32|                     22|                 10|                0.00|      0.20%|
         +---------+------------+------------------+-----------------------+-------------------+--------------------+-----------+

       ```
      - 在界面上以 HTML 的类型展示报告内容。

       设置诊断开始时间为 `2024-02-22 19:26:47`，诊断结束时间为 `2024-06-22 19:27:07`，报告展示格式为 `HTML`，其他字段值根据是否需要来设置。

       ```shell
       obclient [test]>CALL DBMS_WORKLOAD_REPOSITORY.ASH_REPORT(  '2023-09-22 10:26:47',  '2024-06-22 20:27:07', NULL, NULL, NULL, 'HTML', NULL, NULL, NULL);

       ```

       ```shell
             Observer Version: OceanBase 4.2.4.0 (200000342024061210-c4c0c18741e45a1d40889b6147c3132574xxxxxx)
         Operation System Info: Linux(3.10.0-327.ali2019.alios7.x86_64)_x86_64
         User Input Begin Time: 2024-02-22 19:26:47
             User Input End Time: 2024-06-22 19:27:07
             Analysis Begin Time: 2024-06-13 18:24:34
             Analysis End Time: 2024-06-14 17:04:21
                 Elapsed Time: 81586
                 Num of Sample: 16814
         Average Active Sessions: 0.21
         </pre><ul id=110></ul><a class="ash_html" name='Top Active Tenants'></a>          <h2 class="ash_html">Top Active Tenants<br></h2><ul><li class='ash_html'>this section lists top active tenant information</li>
         <li class='ash_html'>Total Count: num of records during ash report analysis time period</li>
         <li class='ash_html'>Wait Event Count: num of records when session is on wait event</li>
         <li class='ash_html'>On CPU Count: num of records when session is on cpu</li>
         <li class='ash_html'>Avg Active Sessions: average active sessions during ash report analysis time period</li>
         <li class='ash_html'>% Activity: activity(cpu + wait) percentage for given tenant</li>

       ```
 3. （可选）在本地查看报告信息。

   将报告内容以 TXT 文件或 HTML 网页的形式查看，这里以生成 HTML 类型为例。

      1. 登录进入物理机。

        ```shell
        [admin@xxxxxx.eu95sqa /home/admin]

        ```
      2. 制作 ASH 报告脚本文件 `ash_report.html`，该脚本文件只需要放在 OBServer 所在机器上即可。

        ```shell
        [admin@xxxxxx.eu95sqa /home/admin]
        $vim ash_report_my.html

        ```
      3. 生成脚本内容。

        ```shell
        tee ash_report_my.html
        CALL DBMS_WORKLOAD_REPOSITORY.ASH_REPORT(  '2023-09-22 10:26:47',  '2024-06-22 20:27:07', NULL, NULL, NULL, 'HTML', NULL, NULL, NULL);
        notee

        ```
      4. 登录数据库，运行 `ash_report_my.html` 脚本。

        ```

        ```shell
        obclient [test]> source ash_report_my.html;

        ```

        脚本运行成功后，会在界面上打印 HTML 类型的报告内容。
      5. 退出数据库，进入物理机查看 `ash_report_my.html` 文件路径。

        ```shell
        [admin@k08j13249.eu95sqa /home/admin]
        $ls
        ALTER                              ash_report_my.html

        ```

        查询到 `ash_report_my.html` 文件路径为 `home/admin/ash_report_my.html`。
      6. 从物理机导出文件到本地。

             1. 打开一个新的 Shell 界面，进入到需要保存文件的路径下。

               ```shell
               PS C:\Users\xxx\Desktop\ASH>

               ```
             2. 使用 `scp` 命令将 `ash_report_my.html` 文件从物理机导入到本机。

               ```shell
               scp admin@xx.xx.xx.xx:/home/admin/ash_report_my.html  /

               ```
             3. 在本地路径下打开 `ash_report_my.html` 文件查看报告信息。。

1. 使用 `SYS` 用户登录到集群的 Oracle 租户，进入 OceanBase 数据库。

   ```shell
   $ obclient -h172.xx.xxx.xxx -Pxxxx -usys@oracle -pxxxx -A

   ```
 2. 通过 `SET SERVEROUTPUT ON` 语句输出打印内容。

   ```shell
   obclient [SYS]> SET SERVEROUTPUT ON;

   ```
 3. 在控制台界面展示报告信息。

       ```shell
       obclient [SYS]>CALL DBMS_WORKLOAD_REPOSITORY.ASH_REPORT(TO_DATE('2024-02-22 19:26:47', 'YYYY-MM-DD HH24:MI:SS'), TO_DATE('2024-06-22 19:27:07', 'YYYY-MM-DD HH24:MI:SS'), REPORT_TYPE=> 'TEXT');

       ```

       ```shell
               ASH Report
                   Cluster Name: test424
               Observer Version: OceanBase 4.2.4.0 (200000342024061210-c4c0c18741e45a1d40889b6147c313257xxxxxxxxx)
           Operation System Info: Linux(3.10.0-327.ali2019.alios7.x86_64)_x86_64
           User Input Begin Time: 2024-02-2219:26:47
             User Input End Time: 2024-06-2219:27:07
             Analysis Begin Time: 2024-06-1318:26:41
               Analysis End Time: 2024-06-1414:51:12
                   Elapsed Time: 73471
                   Num of Sample: 14750
         Average Active Sessions: 0.20
         Top Active Tenants:
           - this section lists top active tenant information
           - Total Count: num of records during ash report analysis time period
           - Wait Event Count: num of records when session is on wait event
           - On CPU Count: num of records when session is on cpu
           - Avg Active Sessions: average active sessions during ash report analysis time period
           - % Activity: activity(cpu + wait) percentage for given tenant
         +---------+------------+------------------+-----------------------+-------------------+--------------------+-----------+
         |Tenant ID|Session Type|       Total Count|       Wait Event Count|       On CPU Count| Avg Active Sessions| % Activity|
         +---------+------------+------------------+-----------------------+-------------------+--------------------+-----------+
         |     1004|  BACKGROUND|             14725|                   1670|              13055|                0.20|     99.83%|
         |     1004|  FOREGROUND|                25|                     11|                 14|                0.00|      0.17%|
         +---------+------------+------------------+-----------------------+-------------------+--------------------+-----------+

       ```shell
       obclient [SYS]>CALL DBMS_WORKLOAD_REPOSITORY.ASH_REPORT(TO_DATE('2024-02-22 19:26:47', 'YYYY-MM-DD HH24:MI:SS'), TO_DATE('2024-06-22 19:27:07', 'YYYY-MM-DD HH24:MI:SS'), REPORT_TYPE=> 'HTML');

       ```

       ```shell
               Observer Version: OceanBase 4.2.4.0 (200000342024061210-c4c0c18741e45a1d40889b6147c313257xxxxxxxxx)
           Operation System Info: Linux(3.10.0-327.ali2019.alios7.x86_64)_x86_64
           User Input Begin Time: 2024-02-2219:26:47
             User Input End Time: 2024-06-2219:27:07
             Analysis Begin Time: 2024-06-1318:26:41
               Analysis End Time: 2024-06-1414:54:29
                   Elapsed Time: 73668
                   Num of Sample: 14806
         Average Active Sessions: 0.20
         </pre><ul id=110></ul><a class="ash_html" name='Top Active Tenants'></a>          <h2 class="ash_html">Top Active Tenants<br></h2><ul><li class='ash_html'>this section lists top active tenant information</li>
         <li class='ash_html'>Total Count: num of records during ash report analysis time period</li>
         <li class='ash_html'>Wait Event Count: num of records when session is on wait event</li>
         <li class='ash_html'>On CPU Count: num of records when session is on cpu</li>
         <li class='ash_html'>Avg Active Sessions: average active sessions during ash report analysis time period</li>
         <li class='ash_html'>% Activity: activity(cpu + wait) percentage for given tenant</li>

       ```
 4. （可选）在本地查看报告信息。

        ```shell
        [admin@xxxxxx.eu95sqa /home/admin]
        $vim ash_report.html

        ```shell
        set serveroutput on;
        tee ash_report.html
        CALL DBMS_WORKLOAD_REPOSITORY.ASH_REPORT(        TO_DATE('2024-02-22 19:26:47', 'YYYY-MM-DD HH24:MI:SS'),        TO_DATE('2024-06-22 19:27:07', 'YYYY-MM-DD HH24:MI:SS'), REPORT_TYPE=> 'HTML'   );
        notee

        ```
      4. 登录数据库，运行 `ash_report.html` 脚本。

        ```

        ```shell
        obclient [SYS]> source ash_report.html;

        ```

        脚本运行成功后，会在界面上打印 HTML 类型的报告内容。
      5. 退出数据库，进入物理机查看 `ash_report.html` 文件路径。

        ```shell
        [admin@k08j13249.eu95sqa /home/admin]
        $ls
        ALTER                              ash_report.html

        ```

        查询到 `ash_report.html` 文件路径为 `home/admin/ash_report.html`。
      6. 从物理机导出文件到本地。

               ```
             2. 使用 `scp` 命令将 `ash_report.html` 文件从物理机导入到本机。

               ```shell
               scp admin@xx.xx.xx.xx:/home/admin/ash_report.html  /

               ```
             3. 在本地路径下打开 `ash_report.html` 文件查看报告信息。。

## 相关文档

- [ASH 简介](https://www.oceanbase.com/docs/common-oceanbase-database-cn-1000000001500500)。
 - [分析 ASH 报告](https://www.oceanbase.com/docs/common-oceanbase-database-cn-1000000001500501)。

 上一篇 下一篇 ![有帮助](https://gw.alipayobjects.com/mdn/ob_asset/afts/img/A*y6ocSqN8cqsAAAAAAAAAAAAAARQnAQ)![无帮助](https://gw.alipayobjects.com/mdn/ob_asset/afts/img/A*BG9IQJyLHF8AAAAAAAAAAAAAARQnAQ)![反馈](https://gw.alipayobjects.com/mdn/ob_asset/afts/img/A*eTWdQKCRKHwAAAAAAAAAAAAAARQnAQ)[AI](https://www.oceanbase.com/obi) 咨询热线
