Hologres provides slow query logs. By default, Hologres logs data manipulation language (DML) statements that take more than 100 ms to execute and all data definition language (DDL) statements. Hologres provides the SQL diagnosis feature based on slow query logs. The SQL diagnosis feature allows you to analyze query trends and details from different dimensions. This helps you understand the usage of instances and optimize the instances to achieve better performance. This topic describes how to use the SQL diagnosis feature.
Diagnostic items and suggestions
The following table describes the diagnostic items provided by the SQL diagnosis feature.
Diagnostic item | Description |
Total number of queries | Displays the total number of queries that are performed in a specified time period. |
Successful Query | Displays the total number of queries that are successfully performed in a specified time period. |
Failed Query | Displays the total number of failed queries in a specified time period. |
Failed Query details | Displays the error codes, number of failures for each type of error code, typical queries, and failure details to facilitate the troubleshooting of failed queries. You can use the Query Insight feature to view more query details. You can also identify the causes of issues based on the error codes. For more information about the Query Insight feature, see Query Insight. For more information about the error codes, see Error codes in this topic. |
Success and Failure Query Trends | Displays the trends of the numbers of successful queries and failed queries in a specified time period. This allows you to obtain the overall running status of the queries in the current instance. |
Time consumption percentage trend of Query | Displays the trend of execution durations of queries in a specified time period. By default, only the execution durations of the following statements are collected: |
DML trend | Displays the trends of the numbers of times that different types of DML queries are performed in a specified time period. By default, the statistics on only the following types of DML statements are collected: |
DDL trend | Displays the trends of the numbers of times that different types of DDL queries are performed in a specified time period. By default, the statistics on only the following types of DDL statements are collected: |
The percentage of query application sources | Displays the proportion or trend of queries based on the You can analyze the applications that initiate the largest number of queries. To help you better observe abnormal tasks, we recommend that you specify different |
Percentages of queries in the user dimension | Displays the proportion or trend of queries based on the You can view the number of queries that are performed by using each account in a visualized manner. To facilitate troubleshooting, we recommend that you use different accounts to run different tasks. |
Query trend of the execution engine | Displays the trends of the numbers of queries that are performed by using different engines in a specified time period. Hologres uses different engines for different queries based on query characteristics. The engines include Hologres Query Engine (HQE), PostgreSQL Query Engine (PQE), SDK, and FixedQE. For more information about the engines, see Architecture. We recommend that you do not perform PQE queries. You can perform HQE queries instead of PQE queries to achieve better performance. |
Usage notes
The SQL diagnosis feature does not collect data of system-related SQL statements. The following code shows the filter conditions:
WHERE usename != 'system' AND client_addr != '127.0.0.1' AND (application_name IS NULL OR application_name NOT IN ('AutoPartition', 'holoweb_system', 'HgGenInQuery'))
By default, the
hologres.hg_query_log
table logs DML statements that take more than1s
to execute and all DDL statements, and the SQL diagnosis feature collects data of all DML and DDL statements that take more than100 ms
to execute. In this case, the amount of data in thehologres.hg_query_log
table may be less than the amount of data collected by the SQL diagnosis feature. To resolve this issue, you can change the value of thelog_min_duration_statement
parameter to100 ms
. For more information, see the "log_min_duration_statement" section in Query and analyze slow query logs.Both the SQL diagnosis feature and slow query logs allow you to query data only in the previous month.
Data is updated on the next day. Therefore, you can only query data in the previous month starting from the previous day. You can filter data by time based on your business requirements. By default, the data of the previous day is displayed. You can filter data by time based on your business requirements.
The permission policy for SQL diagnosis data is the same as the permission policy for slow query logs. For more information, see the "Grant query permissions to users" section in Query and analyze slow query logs.
Procedure
This section describes how to use HoloWeb to view SQL diagnosis data in a visualized manner.
Log on to the HoloWeb console. For more information, see Connect to HoloWeb.
In the top navigation bar, click Diagnostics and Optimization.
In the left-side navigation pane, choose Instance diagnosis > SQL diagnosis.
In the upper part of the SQL diagnosis page, configure the query conditions.
The following table describes the query condition parameters.
Parameter
Required
Description
Instance Name
Yes
The name of the instance whose slow queries you want to query. By default, the connected instance is selected.
Time
Yes
The time range of slow queries. By default, Yesterday is selected. The longest time range is the previous month.
Click Submission. The query result is displayed.
Intelligent SQL diagnosis
The SQL Editor tab in the HoloWeb console displays SQL diagnosis information if a query fails. The Query Insight page also provides the intelligent SQL diagnosis feature, which allows the system to automatically return the cause and solution of a failed query to the SQL Editor tab. This way, you can handle failed queries in a more convenient manner.
Error codes
Error code | Description | Common error message | Solution |
HG_ERRCODE_FDW_ERROR | An error message is reported when metadata of the MaxCompute table is imported to Hologres. In most cases, this issue occurs because the MaxCompute table of the type is not supported by Hologres. |
| For more information, see HG_ERRCODE_FDW_ERROR. |
ERRCODE_FDW_ERROR | An error message is reported during a query by using a foreign table. |
| For more information, see ERRCODE_FDW_ERROR. |
| A uniqueness constraint violation exists. In most cases, this error code is returned when duplicate primary key values exist during data writes. |
|
|
| A check constraint violation exists. In most cases, this error code is returned when you write a data record whose partition key value is different from the partition key value specified in the statement. For example, you write data whose partition key value is |
| Make sure that you write data whose partition key value is the same as the partition key value specified in the statement. |
| A NOT NULL constraint violation exists. In most cases, this error code is returned when you write NULL data to NOT NULL columns. |
| Process dirty data. |
ERRCODE_UNDEFINED_TABLE | The table does not exist. In most cases, this error code is returned when the table is created but the metadata is not updated or the TRUNCATE or DROP operation is performed on the table during the query. |
| Use the Query Insight feature to check whether the TRUNCATE or DROP operation is performed on the table during the query. Then, retry the task. For more information, see Query Insight. |
| An unexpected internal error occurs. For example, the instance breaks down or the query is unexpectedly interrupted. |
| None. |
| The query is canceled. In most cases, this error code is returned when the client times out or the TRUNCATE or DROP operation is performed on the table. |
| For more information, see Manage queries. |
| A specific feature is not supported. |
| For more information, see FAQ about SQL statements. |
ERRCODE_UNDEFINED_OBJECT | An undefined object is specified in the SQL statement. In most cases, this error code is returned when a column or table group specified in the SQL statement does not exist. |
|
|
| Required permissions are not granted to the account. Authorization is required. |
| For more information, see Permissions on Hologres instances. |
| An out of memory (OOM) error occurs due to insufficient memory for queries. |
| For more information, see FAQ about OOM. |
| Data types mismatch. In most cases, this error code is returned when the data type of a field specified in the SQL statement does not match the actual data type of the field. |
| Make sure that the data type specified in the SQL statement matches the actual data type of the field. |
| The SQL statement specifies division by |
| Process dirty data, or configure Grand Unified Configuration (GUC) parameters to allow division by 0. For more information, see the "Functions" section in Migrate data from MySQL to Hologres. |
ERRCODE_STRING_DATA_RIGHT_TRUNCATION | A string is truncated from the right. In most cases, this error code is returned when the length of a field value of the VARCHAR type exceeds the upper limit that is specified when the table is created. |
| Create another table and modify the upper limit on the length of fields of the VARCHAR type. You can also set the data type to TEXT. |
| An upper limit specified in Hologres is exceeded. For example, the number of partitions that you want to scan, the number of data rows that you want to read, or the number of bytes that you want to read in a foreign table exceeds the upper limit. |
| For more information about how to fix the issue that an upper limit is exceeded when you query data by using foreign tables, see FAQ about integration with MaxCompute. |
ERRCODE_SYNTAX_ERROR | The SQL syntax is invalid. |
| Check the syntax of the SQL statement. |
ERRCODE_UNDEFINED_FUNCTION | The function syntax is invalid, no extension is created, or the function is not supported. |
| Use functions based on function syntaxes to prevent issues such as invalid syntax or no extension. For more information, see Functions. |
ERRCODE_E_R_E_READING_SQL_DATA_NOT_PERMITTED | You are not granted the read permissions on foreign tables. |
| For more information, see Permissions on MaxCompute. |
| Duplicate objects exist. In most cases, this error code is returned when you create duplicate extensions, publications, or roles. |
| Do not create duplicate objects. |
| The text expression is invalid. In most cases, this error code is returned when you convert an invalid string into another data type. For example, you convert an empty string ("") into the INT data type. |
| Process dirty data. |
ERRCODE_BAD_COPY_FILE_FORMAT | The format of files or data on which the COPY operation is performed is invalid. In most cases, this error code is returned when the source data contains a delimiter, such as a space, that is specified in the COPY statement. As a result, the number of columns in the source table is different from the number of columns in the destination table. |
| Process dirty data. |
ERRCODE_UNDEFINED_COLUMN | The query statement defines a column that does not exist. |
| Check the syntax of the SQL statement. |
ERRCODE_NUMERIC_VALUE_OUT_OF_RANGE | Data values are beyond the specified range.
|
| Check for dirty data or type definition errors and modify data types of columns. |
ERRCODE_DATETIME_FIELD_OVERFLOW | A value overflow occurs in columns of the TIMESTAMP, TIMESTAMPZ, DATE, TIME, or TIMETZ data type. For example, the value |
| Process dirty data. |
ERRCODE_INVALID_PARAMETER_VALUE | The parameter values are invalid. You can troubleshoot the error based on the error message. For example, the error message |
| Check the syntax of the SQL statement. |
ERRCODE_INVALID_DATETIME_FORMAT | The date format is invalid. For example, the format of the date in the |
| Process dirty data. |
ERRCODE_CHARACTER_NOT_IN_REPERTOIRE | Some characters are not supported by the encoding format. In most cases, this error code is returned when a character is not supported by UTF-8. |
| Process dirty data. |
ERRCODE_DUPLICATE_TABLE | Duplicate tables exist. In most cases, this error code is returned when you create a table that has the same name as an existing table. |
| Do not create a table that has the same name as an existing table. |
ERRCODE_UNTRANSLATABLE_CHARACTER | Some characters cannot be converted into a specified format. |
Note Characters encoded in UTF-8 have no equivalent characters in GBK. | Process dirty data. |
ERRCODE_GROUPING_ERROR | The GROUP BY clause is invalid. |
| Check the syntax of the SQL statement. Make sure that the fields of aggregate functions are included in the GROUP BY clause. |
| The transaction status is invalid. This error code is returned when transaction-related operations are invalid. For example, the CALL SET_TABLE_PROPERTY statement that is used to create a distribution key for a table and the statement that is used to create the table are not included in the same transaction. |
| Execute the |
ERRCODE_AMBIGUOUS_COLUMN | A column name in the statement is ambiguous. In most cases, this error code is returned when a column name in the SQL statement may indicate columns in different tables. For example, in the |
| Check the syntax of the SQL statement. |
ERRCODE_DUPLICATE_COLUMN | Duplicate columns exist. In most cases, this error code is returned when a field is declared multiple times during table creation. |
| Check the syntax of the SQL statement. |
ERRCODE_AMBIGUOUS_FUNCTION | The function is invalid. A function supports input parameters of various data types. In most cases, this error code is returned when the data type of input parameters is not supported. | For example, the to_char function supports
| Check the syntax of the SQL statement. |
ERRCODE_INVALID_COLUMN_DEFINITION | The column definition is invalid. In most cases, this error code is returned when no precision is specified for columns of the NUMERIC or DECIMAL data type in Hologres tables. |
| Process dirty data. |
ERRCODE_INVALID_CATALOG_NAME ERRCODE_UNDEFINED_DATABASE | The specified database does not exist. | None. | Check whether the database exists. |
ERRCODE_CANNOT_COERCE | Conversion between two data types is not supported. |
| Check the syntax of the SQL statement. |
ERRCODE_DEPENDENT_OBJECTS_STILL_EXIST | In most cases, this error code is returned when you try to delete an object on which one or more other existing objects depend. For example, when you delete a schema, the tables in the schema still exist. | None. | Process the dependencies. For more information, see Delete an account. |
ERRCODE_UNDEFINED_SCHEMA or ERRCODE_INVALID_SCHEMA_NAME | The specified schema does not exist. |
| Check whether the schema exists. If the schema does not exist, create a schema. |
ERRCODE_DUPLICATE_DATABASE | Duplicate databases exist. This error code is returned when you create a duplicate database. | None. | Do not create duplicate databases. |
AutoAnalyze-Failed | The auto-analyze feature fails. |
| In most cases, this error code is caused by backend issues. Submit a ticket for troubleshooting. |
Import Foreign Table Not Found | The foreign table cannot be found. |
| Check whether the foreign table exists. |
Cannot Acquire Lock In Time | In most cases, this error code is returned due to failures in acquiring locks. For example, if you perform high-concurrency queries and drop operations on the same table, a deadlock occurs on the backend node. As a result, all operations on the table are stuck and the error code is returned. |
| For more information, see Locks and lock troubleshooting. |
| Unexpected errors occur. |
| Submit a ticket for troubleshooting. |