SQL execution errors are common in database O&M and can directly impact business operations. Many factors can cause SQL execution errors, such as failed database connection, insufficient user privileges, syntax errors, or data not meeting query conditions.
To help you quickly identify the root cause and efficiently resolve SQL execution errors, the following sections provide a clear and practical troubleshooting process. This process offers step-by-step guidance to improve issue resolution efficiency and minimize business impact, thereby supporting your daily O&M work.
Procedure
When an SQL execution error occurs, you can troubleshoot the issue based on the following procedure.
After an SQL execution error occurs, view the SQL error message. If the error message contains an error code, troubleshoot the issue based on the error code. If the error message does not contain an error code, determine the error type. The error may be an application execution error or an SQL execution error:
If the error is an SQL execution error, determine whether the error can be manually reproduced.
If the error can be reproduced, reproduce the error scenario. Connect to the OceanBase cluster through port 2881 or 2883 based on the original scenario and execute the original SQL statement to reproduce the error scenario.
After reproducing the SQL execution error, perform the following steps to collect information for troubleshooting.
1. Execute the following statement to obtain `trace_id`:
<main id="notice" type='notice'>
<h4>Notice</h4>
<p>You must execute the following statement immediately after the SQL statement that causes the error is executed; otherwise, <code>trace_id</code> of the error SQL statement cannot be obtained. </p>
</main>
:::tab
tab MySQL mode
The following statement is executed to obtain `trace_id` in MySQL mode:
```shell
obclient> SELECT last_trace_id();
```
tab Oracle mode
The following statement is executed to obtain `trace_id` in Oracle mode:
```shell
obclient> SELECT last_trace_id() FROM DUAL;
```
:::
2. Obtain the host information based on the obtained `trace_id`.
Generally, an OceanBase cluster is deployed across multiple nodes. You can execute the following SQL statement to obtain the node that actually executed the SQL statement, and then filter logs based on the node.
:::tab
tab MySQL mode
Execute the following statement in MySQL mode:
```shell
obclient> SELECT * FROM oceanbase.GV$OB_SQL_AUDIT WHERE trace_id=last_trace_id;
```
Replace `last_trace_id` with `trace_id` obtained in the previous step.
tab Oracle mode
Execute the following statement in Oracle mode:
```shell
obclient> SELECT * FROM SYS.GV$OB_SQL_AUDIT WHERE trace_id=last_trace_id;
```
Replace `last_trace_id` with `trace_id` obtained in the previous step.
:::
Based on the query result in the `GV$OB_SQL_AUDIT` view, the host corresponding to `svr_ip` is the host that actually executed the SQL statement.
3. Use the `ssh` command to log in to the host based on the obtained host information.
4. Go to the log directory.
Taking the installation directory of OceanBase Database, `/home/admin/oceanbase`, as an example. The specific log storage path depends on the actual environment.
```shell
cd /home/admin/oceanbase/log
```
5. Execute the following command to filter relevant logs.
```shell
grep "${trace_id}" observer.log
```
```shell
grep "${trace_id}" observer.log.xxx
```
Replace `${trace_id}` with `trace_id` obtained in the previous steps. `observer.log.xxx` is a log file with a timestamp. Replace `xxx` with the actual timestamp in the log file name based on the timestamp when you reproduce the SQL execution error.
6. Based on the information provided in the logs, analyze the issue based on the error code or error message.
For more information about logs and error codes, see [Overview of logs](../800.logging/100.logging-overview.md) and [Overview of error information](../../700.reference/500.system-reference/600.error-code-of-mysql-mode/100.use-error-information-of-mysql-mode.md).
If the information in the logs is unclear, contact technical engineers for assistance.
Typical cases
The following cases are typical SQL execution error troubleshooting cases.
After the SQL error is reproduced, the error code is returned in the result.
- When a
SELECTstatement contains manyORconditions, or manyAND-connectedINconditions, or manyAND NOTconditions, an error is returned, specificallySELECT -4013, No memory or reach tenant memory limit.
- When a
The error code is contained in the log.
An error is returned when processing a
longtextfield by executing an SQL statement, specificallyErrorCode=5098.An error is returned during SQL execution:
error 4119 (RPC packet to send too long). You can query theobserver.logfile using thetrace_idand find the informationobrpc packet payload execced its limit.
Other error messages are contained in the log.
- If the filter conditions in an SQL statement involve more than 64 fields, an error is returned:
-4002 Invalid argument.
- If the filter conditions in an SQL statement involve more than 64 fields, an error is returned:
After the SQL error is reproduced, the error code is returned in the result.
- A query statement that contains the
c1,c2, andc3columns returns aninternal errorwith the error codeORA-00600when executed. The statement contains columnsc1andc2that hit indexes, andc1orc2contains multipleINexpressions. In addition,c1,c2, andc3form a vector expression.
- A query statement that contains the
The error code is returned after SQL execution, and the error code is combined with the error code information in the log.
- An error is returned when executing an SQL statement:
Timeoutwith the error codeORA-00600.
- An error is returned when executing an SQL statement: