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:
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:
Log in 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
BTIMEandETIMEparameters must be set. - The
REPORT_TYPEparameter can be set toTEXTonly. - Set the
SQL_ID,TRACE_ID, andWAIT_CLASSparameters 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 in to the database and run 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;