The Show Trace feature can interactively display the call chain of the last executed SQL request and the time consumed in each phase of the chain, thereby facilitating performance analysis and optimization. You can use the Show Trace feature to conveniently identify performance bottlenecks.
Supported versions of the components
OceanBase Database: V4.2.0 and later
OceanBase Database Proxy (ODP): V4.2.0 and later
OceanBase Cloud Platform (OCP): V4.0.3 and later
Considerations
OceanBase Database supports the Show Trace feature starting from V4.2.0 and uses the OceanBase 2.0 protocol. Pay attention to the following points about this feature:
When you use the end-to-end tracing feature along with components of the supported versions, you can use a session-level switch to turn on session-level Show Trace capabilities. Then, the information about each SQL interaction with ODP and OceanBase Database will be recorded. After an SQL request is executed, you can run the
show tracecommand to query the diagnostic information about the SQL execution record.By default, the Show Trace feature is disabled. The protocol-based transmission of the diagnostic information incurs extra overhead in parsing, transmission, and record processing. This degrades the performance. Therefore, by default, components do not record Show Trace information.
Like the end-to-end tracing feature, the Show Trace feature uses a protocol and is implemented based on interactions. If the version of a component is incorrect or Show Trace is disabled, the results of interactions between the upstream and downstream components are affected. The following scenarios may exist.
If the Show Trace feature is not supported or is disabled in OceanBase Database, the overall Show Trace capabilities are unavailable.
If Show Trace is supported and enabled in OceanBase Database but ODP does not support Show Trace, you can run the
show tracecommand to obtain the interaction information about the last SQL request. However, you can obtain only the information about interactions in OceanBase Database.If Show Trace is supported and enabled in OceanBase Database and ODP, you can run the
show tracecommand to obtain the interaction information about the last SQL request. However, you can obtain only the information about interactions in ODP and OceanBase Database.
Procedure
Step 1: Configure ODP
Log in to the OceanBase cluster by using the root@sys user and execute the following operations.
Enable the OceanBase 2.0 protocol between ODP and OceanBase Database.
This operation allows ODP to obtain the statistics of the OBServer node. The configuration method is as follows.
obclient> alter proxyconfig set enable_ob_protocol_v2 = True;Enable the trace statistics of ODP.
Set enable_full_link_trace to
Trueto enable the end-to-end tracing feature.obclient> alter proxyconfig set enable_full_link_trace = True;
Step 2: Enable the Show Trace feature and execute the target SQL query
Log in to the OceanBase cluster by using a user tenant and execute the following operations.
Enable session-level Show Trace.
Set ob_enable_show_trace to
ONto enable the Show Trace feature.obclient> set ob_enable_show_trace= 'ON';Execute the target SQL request, which is
show tables;in the following example.obclient> show tables;Output:
+----------------------------+ | Tables_in_test | +----------------------------+ | t | | t1 | | t2 | +----------------------------+ 3 rows in set
Step 3: Use the Show Trace feature
You can run the show trace; command to obtain the result set or run the show trace format='json'; command to obtain the result set in JSON format.
Run the
show trace;command to obtain the result set.obclient> show trace;Output:
+-----------------------------------------------+----------------------------+------------+ | Operation | StartTime | ElapseTime | +-----------------------------------------------+----------------------------+------------+ | ob_proxy | 2026-01-08 15:17:24.555215 | 12.414 ms | | ├── ob_proxy_partition_location_lookup | 2026-01-08 15:17:24.555411 | 0.010 ms | | ├── ob_proxy_server_process_req | 2026-01-08 15:17:24.555813 | 10.150 ms | | └── com_query_process | 2026-01-08 15:17:24.555989 | 10.265 ms | | └── mpquery_single_stmt | 2026-01-08 15:17:24.556058 | 10.172 ms | | ├── sql_compile | 2026-01-08 15:17:24.556137 | 7.300 ms | | │ ├── pc_get_plan | 2026-01-08 15:17:24.556230 | 0.016 ms | | │ └── hard_parse | 2026-01-08 15:17:24.556370 | 7.014 ms | | │ ├── parse | 2026-01-08 15:17:24.556396 | 0.044 ms | | │ ├── resolve | 2026-01-08 15:17:24.556526 | 1.866 ms | | │ ├── rewrite | 2026-01-08 15:17:24.558557 | 2.020 ms | | │ ├── optimize | 2026-01-08 15:17:24.560613 | 1.928 ms | | │ └── code_generate | 2026-01-08 15:17:24.562580 | 0.428 ms | | └── sql_execute | 2026-01-08 15:17:24.563462 | 2.457 ms | | ├── open | 2026-01-08 15:17:24.563469 | 0.089 ms | | ├── response_result | 2026-01-08 15:17:24.563614 | 1.620 ms | | │ └── do_local_das_task | 2026-01-08 15:17:24.563716 | 1.025 ms | | └── close | 2026-01-08 15:17:24.565277 | 0.342 ms | | ├── close_das_task | 2026-01-08 15:17:24.565294 | 0.028 ms | | └── end_transaction | 2026-01-08 15:17:24.565551 | 0.036 ms | +-----------------------------------------------+----------------------------+------------+ 20 rows in setYou can first demarcate the issue based on the result. Specifically, you can analyze the time consumption at the following timestamps to quickly learn about the overall execution time in the database to facilitate further analysis and optimization.
ob_proxy is the start timestamp of ODP. It records the duration from the time when ODP receives an SQL request to the time when ODP sends a response to the client.
ob_proxy_server_process_req is the duration from the time when an SQL request is sent to the time when the first response is received from the OBServer node. It equals the value of the request processing time on the OBServer node plus the network transmission time for sending the response.
com_query_process is the total timestamp of OceanBase Database. It records the duration from the time when the OBServer node receives an SQL request to the time when the OBServer node returns a response.
Run the
show trace format='json';command to obtain the result set in JSON format.Run the
show trace format = 'json';command to obtain the result set in JSON format. You can format the result set to facilitate collection and analysis, as shown in the following figure.
You can repeatedly run the show trace; or show trace format='json'; command to view the result in real time.
Step 4: Disable the Show Trace feature
After analysis, run the following command to disable the session-level Show Trace feature to avoid affecting the performance.
obclient> set ob_enable_show_trace= 'OFF';