OceanBase logo

OceanBase

A unified distributed database ready for your transactional, analytical, and AI workloads.

DEPLOY YOUR WAY

OceanBase Cloud

The best way to deploy and scale OceanBase

OceanBase Enterprise

Run and manage OceanBase on your infra

TRY OPEN SOURCE

OceanBase Community Edition

The free, open-source distributed database

OceanBase seekdb

Open source AI native search database

Customer Stories

Real-world success stories from enterprises across diverse industries.

View All
BY USE CASES

Mission-Critical Transactions

Global & Multicloud Application

Elastic Scaling for Peak Traffic

Real-time Analytics

Active Geo-redundancy

Database Consolidation

Resources

Comprehensive knowledge hub for OceanBase.

Blog

Live Demos

Training & Certification

Documentation

Official technical guides, tutorials, API references, and manuals for all OceanBase products.

View All
PRODUCTS

OceanBase Cloud

OceanBase Database

Tools

Connectors and Middleware

QUICK START

OceanBase Cloud

OceanBase Database

BEST PRACTICES

Practical guides for utilizing OceanBase more effectively and conveniently

Company

Learn more about OceanBase – our company, partnerships, and trust and security initiatives.

About OceanBase

Partner

Trust Center

Contact Us

International - English
中国站 - 简体中文
日本 - 日本語
Sign In
Start on Cloud

A unified distributed database ready for your transactional, analytical, and AI workloads.

DEPLOY YOUR WAY

OceanBase Cloud

The best way to deploy and scale OceanBase

OceanBase Enterprise

Run and manage OceanBase on your infra

TRY OPEN SOURCE

OceanBase Community Edition

The free, open-source distributed database

OceanBase seekdb

Open source AI native search database

Customer Stories

Real-world success stories from enterprises across diverse industries.

View All
BY USE CASES

Mission-Critical Transactions

Global & Multicloud Application

Elastic Scaling for Peak Traffic

Real-time Analytics

Active Geo-redundancy

Database Consolidation

Comprehensive knowledge hub for OceanBase.

Blog

Live Demos

Training & Certification

Documentation

Official technical guides, tutorials, API references, and manuals for all OceanBase products.

View All
PRODUCTS
OceanBase CloudOceanBase Database
ToolsConnectors and Middleware
QUICK START
OceanBase CloudOceanBase Database
BEST PRACTICES

Practical guides for utilizing OceanBase more effectively and conveniently

Learn more about OceanBase – our company, partnerships, and trust and security initiatives.

About OceanBase

Partner

Trust Center

Contact Us

Start on Cloud
编组
All Products
    • Databases
    • iconOceanBase Database
    • iconOceanBase Cloud
    • iconOceanBase Tugraph
    • iconInteractive Tutorials
    • iconOceanBase Best Practices
    • Tools
    • iconOceanBase Cloud Platform
    • iconOceanBase Migration Service
    • iconOceanBase Developer Center
    • iconOceanBase Migration Assessment
    • iconOceanBase Admin Tool
    • iconOceanBase Loader and Dumper
    • iconOceanBase Deployer
    • iconKubernetes operator for OceanBase
    • iconOceanBase Diagnostic Tool
    • iconOceanBase Binlog Service
    • Connectors and Middleware
    • iconOceanBase Database Proxy
    • iconEmbedded SQL in C for OceanBase
    • iconOceanBase Call Interface
    • iconOceanBase Connector/C
    • iconOceanBase Connector/J
    • iconOceanBase Connector/ODBC
    • iconOceanBase Connector/NET
icon

OceanBase Database

SQL - V4.3.3

    Download PDF

    OceanBase logo

    The Unified Distributed Database for the AI Era.

    Follow Us
    Products
    OceanBase CloudOceanBase EnterpriseOceanBase Community EditionOceanBase seekdb
    Resources
    DocsBlogLive DemosTraining & Certification
    Company
    About OceanBaseTrust CenterLegalPartnerContact Us
    Follow Us

    © OceanBase 2026. All rights reserved

    Cloud Service AgreementPrivacy PolicySecurity
    Contact Us
    Document Feedback
    1. Documentation Center
    2. OceanBase Database
    3. SQL
    4. V4.3.3
    iconOceanBase Database
    SQL - V 4.3.3
    SQL
    KV
    • V 4.4.2
    • V 4.3.5
    • V 4.3.3
    • V 4.3.1
    • V 4.3.0
    • V 4.2.5
    • V 4.2.2
    • V 4.2.1
    • V 4.2.0
    • V 4.1.0
    • V 4.0.0
    • V 3.1.4 and earlier

    Generate ASH reports

    Last Updated:2025-11-27 02:38:06  Updated
    share
    What is on this page
    SQL syntax
    Procedure
    References

    folded

    share

    You can call the Active Session History (ASH) PL package to generate corresponding ASH reports.

    SQL syntax

    An ASH PL package consists of the following parameters:

    MySQL mode
    Oracle mode
    obclient [oceanbase]> call dbms_workload_repository.ash_report(
      'BTIME', 
      'ETIME', 
      'sql id', 
      'trace id', 
      'wait class');
    
    obclient [SYS]> call dbms_workload_repository.ash_report(     
      BTIME => 'xxxx', 
      ETIME => 'xxxx',  
      SQL_ID => 'xxxx',
      TRACE_ID => 'xxxx', 
      WAIT_CLASS => 'xxxx',
      );
    

    The following table describes the parameters.

    Parameter Description
    BTIME The sampling start time.
    ETIME The sampling end time.
    SQL_ID The SQL ID of the SQL statement to be sampled. If you do not specify this parameter or set the value to NULL, the SQL ID of the statement to be sampled is not limited.
    TRACE_ID The trace ID of the SQL statement to be sampled. If you do not specify this parameter or set the value to NULL, the trace ID of the SQL statement to be sampled is not limited.
    WAIT_CLASS The type of the wait event to be sampled. Specify WAIT_CLASS in accordance with the value of the WAIT_CLASS column in the GV$ACTIVE_SESSION_HISTORY view. If you do not specify this parameter or set it to NULL, the wait event class is not limited.
    REPORT_TYPE The type of the report. At present, only the TEXT type is supported. This parameter is optional.

    You can query the GV$ACTIVE_SESSION_HISTORY view for relevant information in the package. The GV$ACTIVE_SESSION_HISTORY view provides information about session activities. Any database access session that is queued is considered an active session. Each session is sampled based on a set of row data returned by the GV$ACTIVE_SESSION_HISTORY view. All sessions in the session sampling period are displayed in the view. For more information about this view, see GV$ACTIVE_SESSION_HISTORY in MySQL mode and GV$ACTIVE_SESSION_HISTORY in Oracle mode.

    Procedure

    To generate an ASH report in Oracle mode, perform the following steps:

    1. Log in to an Oracle tenant of the OceanBase cluster as the SYS user.

      $ obclient -h172.30.xxx.xxx -Pxxxx -usys@oracle -pxxxx -A
      obclient [SYS]>
      
    2. Call set serveroutput on; to print the output.

      obclient [SYS]> set serveroutput on;
      
    3. Call the ASH PL package and enter the diagnostics start time and end time to generate the report content.

      • Display the report content on the screen.

        obclient [SYS]>call dbms_workload_repository.ash_report(     
          -- The sampling start time.
          to_date('2023-02-22 19:26:47', 'yyyy-MM-dd HH24:mi:ss'), 
          -- The sampling end time.
          to_date('2023-02-22 19:27:07', 'yyyy-MM-dd HH24:mi:ss'),
          -- Sample the SQL statement whose SQL ID is 15B18561C66FCF844D00386749C0DA49.
          sql_id=>'15B18561C66FCF844D00386749C0DA49');
          -- Set TRACE_ID and WAIT_CLASS in a similar way as SQL_ID. Example: trace_id='xxxxxx'.
        Query OK, 0 rows affected (29.49 sec)
        

        Note

        • The BTIME and ETIME parameters must be set.
        • The REPORT_TYPE parameter can be set to TEXT only.
        • Set the SQL_ID, TRACE_ID, and WAIT_CLASS parameters as required.
      • Display the report content in a TXT file.

        1. Generate the report.sql script file.

          vim report.sql
          
          set serveroutput on;
          tee report.txt
          call dbms_workload_repository.ash_report(
                    ## The sampling start time.
                    to_date('2022-01-01 11:11:11', 'yyyy-MM-dd HH24:mi:ss'),
                    ## The sampling end time.
                    to_date('2022-11-10 12:18:36', 'yyyy-MM-dd HH24:mi:ss'),
                    ## Sample the SQL statement whose SQL ID is 15B18561C66FCF844D00386749C0DA49.
                    sql_id=>'15B18561C66FCF844D00386749C0DA49');
                    ## Set TRACE_ID and WAIT_CLASS in a similar way as SQL_ID. Example: trace_id='xxxxxx'.
          notee
          
        2. Log in to the database and run the start report.sql command. The results are printed to the report.txt file.

          $ obclient -h172.30.xxx.xxx -P2881 -usys@oracle -pxxxx -A
          obclient [SYS]> source report.sql;
          

    References

    • ASH
    • Analyze ASH reports

    Previous topic

    ASH
    Last

    Next topic

    Analyze ASH reports
    Next
    What is on this page
    SQL syntax
    Procedure
    References