SQL execution errors are common in database O&M and can directly impact business operations. There are many reasons why SQL errors occur, 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 issues, the following sections provide a clear and practical SQL error troubleshooting process. This process offers specific steps to enhance issue resolution efficiency and minimize business impact, providing strong support for 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 type can be an application execution error or an SQL execution error.
If the error is an application execution error, troubleshoot the issue based on Application exceptions -- error message contains OceanBase error code.
If the error is an SQL execution error, determine whether the error can be manually reproduced.
If the error can be reproduced, reproduce the scenario where the error occurred. Connect to the OceanBase cluster through port 2881 or 2883 based on the original scenario and execute the original SQL statement to reproduce the scenario.
After reproducing the SQL execution error, perform the following steps to collect information for troubleshooting.
Execute the following statement to obtain
trace_id:Notice
You must execute the following statement immediately after the SQL statement that caused the error is executed; otherwise, the
trace_idobtained by executing the following statement will not be that of the SQL statement that caused the error.MySQL modeOracle modeThe statement to obtain
trace_idin MySQL mode is as follows:obclient> SELECT last_trace_id();The statement to obtain
trace_idin Oracle mode is as follows:obclient> SELECT last_trace_id() FROM DUAL;Obtain the host information of the host that actually executed the SQL statement based on the obtained
trace_id.OceanBase clusters are generally deployed across multiple nodes. You can execute the following statement to obtain the node that actually executed the SQL statement and then filter logs based on the node.
MySQL modeOracle modeExecute the following statement in MySQL mode:
obclient> SELECT * FROM oceanbase.GV$OB_SQL_AUDIT WHERE trace_id=last_trace_id;Replace
last_trace_idwith thetrace_idobtained in the previous step.Execute the following statement in Oracle mode:
obclient> SELECT * FROM SYS.GV$OB_SQL_AUDIT WHERE trace_id=last_trace_id;Replace
last_trace_idwith thetrace_idobtained in the previous step.View the
svr_ipcolumn in theGV$OB_SQL_AUDITview. The corresponding host is the host that actually executed the SQL statement.Use the
sshcommand to log in to the host based on the obtained host information.Go to the log directory.
Assume that the installation directory of OceanBase Database is
/home/admin/oceanbase. The specific log path depends on your actual environment.cd /home/admin/oceanbase/logExecute the following command to filter out the required information from the logs.
grep "${trace_id}" observer.loggrep "${trace_id}" observer.log.xxxReplace
${trace_id}with thetrace_idobtained in the previous steps. Replaceobserver.log.xxxwith a log file that contains timestamps.xxxindicates the actual timestamp, which depends on the time when the SQL execution error was reproduced.Based on the information provided in the logs, perform issue analysis based on the error code or error message.
For more information about logs and error codes, see Overview of logs and Overview of error information.
If the information in the logs is unclear, contact technical support for assistance.
Case studies
The following case studies describe typical scenarios where SQL execution errors occur.
After the SQL error is reproduced, the error code is returned in the result.
- When a
SELECTstatement contains a large number ofORconditions, or a large number ofAND-connectedINconditions, or a large number ofAND NOTconditions, an error is returned when the statement is executed:-4013, No memory or reach tenant memory limit.
- When a
The error code is included in the log.
When an SQL statement is executed to process a
longtextfield, an error is returned:ErrorCode=5098.An SQL execution error is returned:
error 4119 (RPC packet to send too long). You can query theobserver.logfile using thetrace_idto find the informationobrpc packet payload execced its limit.
Other error messages are included in the log.
- When the filter conditions of an SQL statement involve more than 64 fields, an error is returned:
-4002 Invalid argument.
- When the filter conditions of 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 contains columns
c1,c2, andc3. Columnsc1andc2hit indexes, and multipleINexpressions are on columnc1orc2.c1,c2, andc3can form a vector expression. When this statement is executed, aninternal erroris returned, with the error codeORA-00600.
- A query statement contains columns
The error code is returned after SQL execution, and the error code is included in the log.
- When an SQL statement is executed, a
Timeouterror is returned, with the error codeORA-00600.
- When an SQL statement is executed, a