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 fields:
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 parameters are described as follows:
| 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$OB_ACTIVE_SESSION_HISTORY view. If you do not specify this field 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$OB_ACTIVE_SESSION_HISTORY view for relevant information in the package. The GV$OB_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$OB_ACTIVE_SESSION_HISTORY view. All sessions in the session sampling period are displayed in the view. For more information about this view in the Oracle mode, see GV$OB_ACTIVE_SESSION_HISTORY.
Procedure
To generate an ASH report in Oracle mode, perform the following steps:
Log on to an Oracle tenant of the OceanBase cluster as the
SYSuser.$ obclient -h172.30.xxx.xxx -Pxxxx -usys@oracle -pxxxx -A obclient [SYS]>Call
set serveroutput on;to print the output.obclient [SYS]> set serveroutput on;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
BTIMEandETIMEfields must be set. - The
REPORT_TYPEfield can be set to text only. - Set the
SQL_ID,TRACE_ID, andWAIT_CLASSfields as required.
- The
Display the report content in a TXT file.
Generate the
report.sqlscript file.vim report.sqlset 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'. noteeLog on to the database and execute the
start report.sqlcommand. The results are printed to thereport.txtfile.$ obclient -h172.30.xxx.xxx -P2881 -usys@oracle -pxxxx -A obclient [SYS]> source report.sql;