Querying and Analyzing Top SQL
Overview
The complex O&M environment of DWS distributed databases is prone to emergencies such as execution plan jumps, unexpected interruptions, and long-running transactions. Traditional O&M approaches cannot reproduce exceptions, trace execution paths, or retain runtime metrics. This makes fault location a resource-intensive and often cyclical process.
To address these challenges, DWS introduces Top SQL monitoring. It tracks both real-time and historical SQL statements to:
- Quickly locate the query statements that affect database performance and consume the most resources.
- Monitor the performance changes of these query statements over time.
- Analyze the query execution plan to determine potential optimization methods.
As a core support tool for database O&M, Top SQL monitoring has been deeply integrated into various scenarios in the production environment to help diagnose system performance, trace SQL deterioration, and trace security audit. The monitoring matrix covers multiple core metrics, such as memory usage, execution time, I/O throughput, network latency, and storage space.
Top SQL Principles
After a job is delivered and executed, the database kernel records job resource information, such as memory, CPU, spilling, I/O, and network information, by using stubs. These information is stored in the lockless queue and then dumped to the dbms_om.gs_wlm_session_info system catalog by the resource management background auxiliary thread. Later, the data is aged periodically by using topsql_retention_time.
Related GUC Parameters
After a cluster is created, top SQL monitoring is enabled by default. This function is controlled by the use_workload_manager, enable_resource_track and enable_resource_record parameters (They default to on). For details about the parameters, see Table 1.
|
Parameter |
Description |
Recommended Value |
||
|---|---|---|---|---|
|
use_workload_manager |
Whether to enable resource management. To enable top SQL monitoring, this parameter must be set to on. |
on |
||
|
enable_resource_track |
Whether to enable real-time resource monitoring. If this function is disabled, real-time top SQL statements will not be recorded and they will not appear in historical top SQL statements. |
on |
||
|
enable_resource_record |
Whether to archive resource monitoring records. When this parameter is enabled, records that have been executed are archived to the corresponding INFO views. This parameter must be set on both CNs and DNs. |
on |
||
|
enable_track_record_subsql |
Whether to archive sub-statement records. That is, this parameter determines whether to record internal statements of stored procedures and anonymous blocks.
|
on |
||
|
resource_track_duration |
Minimum execution time (including queuing time) for archiving statement historical information. If the sum of the queuing time and execution time of a statement is greater than the value of resource_track_duration, the statement information is archived in the top SQL historical views.
|
60s |
||
|
resource_track_subsql_duration |
Minimum execution time of sub-statements dumped in a stored procedure. This parameter is supported only by clusters of version 8.2.1 or later. |
180s |
||
|
resource_track_cost |
Minimum execution cost for resource monitoring on statements in the current session. |
0 |
||
|
resource_track_level |
Resource monitoring level of the current session. The default value is query.
|
query |
||
|
topsql_retention_time |
Data storage retention period of the GS_WLM_SESSION_INFO and GS_WLM_OPERATOR_INFO catalogs in historical top SQL statements, in days. |
30 |
||
|
session_history_memory |
Memory size of historical query views. If the error message "TopSQL lfq is full, failed to save queryid" is displayed, you can run the following SQL statement to query the total memory and used memory of the Top SQL lock-free queue:
|
100 MB |
How to Configure the GUC Parameters
Set the parameters on the DWS console.
- Log in to the DWS console. In the navigation pane, choose Dedicated Clusters > Clusters.
- In the cluster list, find the target cluster and click the cluster name. The Cluster Information page is displayed.
- Click the Parameters tab and modify the parameter values. Then click Save.
Common SQL Statements for Querying the Settings of the GUC Parameters
SELECT name,setting FROM pg_settings WHERE name LIKE '%resource%';

Views and Analysis Methods
The Top SQL monitoring level is determined by the resource_track_level parameter. The value can be query (default), perf, operator_realtime, or operator.
- query: The plan information (similar to the output of EXPLAIN) of SQL statements is recorded in top SQL statements.
- perf: The plan information (similar to the output of EXPLAIN ANALYZE) that contains the actual execution time and number of executed rows is recorded in top SQL statements.
- operator_realtime: The information about the real-time job operators is recorded in top SQL statements, but not persisted in historical top SQL statements.
- operator: The information to be recorded includes the actual execution time, the number of executed rows, and the operator execution.
Top SQL statements are carried by views in Table 2. You can analyze top SQL information based on the fields in the views. For details about the common analysis fields in the views, see Table 3.
|
Level |
Type |
Query Scope |
View |
Description |
|---|---|---|---|---|
|
query/perf |
Real time |
Single CN |
It displays load management information about jobs being executed by the current user on the current CN. |
|
|
All CNs |
It displays load management information about jobs that are being executed on all CNs. |
|||
|
History |
Single CN |
It displays load management information about a completed job executed on the current CN. |
||
|
All CNs |
It displays load management records after job execution on all CNs. |
|||
|
All CNs (The information of classic fields is displayed) |
It displays the top SQL classic fields of jobs executed on all CNs. Only clusters of version 9.1.1.100 or later support this view. |
|||
|
operator_realtime/operator |
Real time |
Single CN |
It displays the operator information about jobs that are being executed on the current CN. |
|
|
All CNs |
It displays the operator information about jobs that are being executed on all CNs. |
|||
|
History |
Single CN |
It displays operator information after job execution on the current CN. |
||
|
All CNs |
It displays operator information after job execution on all CNs. |
|
No. |
Field Name |
Field Description |
Possible Symptoms |
|---|---|---|---|
|
1 |
block_time |
Block time before statement execution. The block time is spent on statement parsing, statement optimization, and job queuing. |
A1: If the value of block_time is large but the value of duration does not change significantly, the job is affected by other jobs and is queued for a long time before being executed. In this case, view the number of jobs whose start time is earlier than start_time and end time is later than finish_time. A2: If the value of block_time is small but the value of duration is large, it indicates the job's delay is not caused by waiting for resources but by its own execution logic. You should investigate changes in data volume and analyze the execution time on each DN. |
|
2 |
start_time |
Time when the statement starts to be executed. |
|
|
3 |
finish_time |
Time when the statement execution ends. |
|
|
4 |
duration |
Execution duration of the statement. |
|
|
5 |
status |
Final statement execution status. Its value can be finished (normal) or aborted (abnormal). |
Check whether the job ends normally. If the job ends abnormally, check the exception causes. |
|
6 |
abort_info |
Exception information displayed if the final statement execution status is aborted. |
|
|
7 |
min_peak_memory |
Minimum memory peak of the statement across all DNs. The unit is MB. |
B1: For a given query, compare the memory usage of several times. The average memory usage can reflect whether the data volume of the data table changes. The value of memory_skew_percent can reflect whether data skew occurs in the data table on each DN. Use Query_plan (see No. 31 in this table) to check whether the job execution plan changes. |
|
8 |
max_peak_memory |
Maximum memory peak of the statement across all DNs. The unit is MB. |
|
|
9 |
average_peak_memory |
Average memory usage during statement execution. The unit is MB. |
|
|
10 |
memory_skew_percent |
Memory usage skew of the statement among DNs. |
|
|
11 |
min_spill_size |
Minimum spilled data among all DNs when a spill occurs. The unit is MB. |
C1: These fields are critical for diagnosing queries with data spills. A sharp increase in spilled data indicates that there is a large increase in underlying table volume or an inefficient execution plan. You can further analyze the query_plan and view the spill_skew_percent metric to check whether severe data skew occurs. |
|
12 |
max_spill_size |
Maximum spilled data among all DNs when a spill occurs. The unit is MB. |
|
|
13 |
average_spill_size |
Average spilled data among all DNs when a spill occurs. The unit is MB. |
|
|
14 |
spill_skew_percent |
DN spill skew when a spill occurs. |
|
|
15 |
min_dn_time |
Minimum execution time of the statement across all DNs, in milliseconds |
D1: If the execution time of a query on DNs is severely skewed, check whether the partitioning and distribution columns of the data table are properly set. If not, the system may execute tasks on a few DNs instead of many DNs, prolonging the execution. |
|
16 |
max_dn_time |
Maximum execution time of the statement across all DNs, in milliseconds. |
|
|
17 |
average_dn_time |
Average execution time of the statement across all DNs, in milliseconds. |
|
|
18 |
dntime_skew_percent |
Execution time skew of the statement across all DNs. |
|
|
19 |
min_cpu_time |
Minimum CPU time of the statement across all DNs, in milliseconds. |
E1: The CPU execution time indicates the actual execution time allocated to the job. If duration increases but the average CPU execution time does not change, there may be many computing-intensive jobs being executed concurrently. The job execution duration is prolonged due to CPU preemption. |
|
20 |
max_cpu_time |
Maximum CPU time of the statement across all DNs, in milliseconds. |
|
|
21 |
total_cpu_time |
Total CPU time of the statement across all DNs, in milliseconds. |
|
|
22 |
cpu_skew_percent |
CPU time skew of the statement among DNs. |
|
|
23 |
min_dn_time |
Minimum execution time of the statement across all DNs, in milliseconds. |
D1: If the execution time of a query on DNs is severely skewed, check whether the partitioning and distribution columns of the data table are properly set. If not, the system may execute tasks on a few DNs instead of many DNs, prolonging the execution. |
|
24 |
max_dn_time |
Maximum execution time of the statement across all DNs, in milliseconds. |
|
|
25 |
average_dn_time |
Average execution time of the statement across all DNs, in milliseconds. |
|
|
26 |
dntime_skew_percent |
Execution time skew of the statement across all DNs. |
|
|
27 |
min_peak_iops |
Minimum peak IOPS of the statement across all DNs. |
F1: If a job's duration increases without a corresponding rise in data volume, memory, CPU time, or spilled data, the most likely cause is an I/O bottleneck. I/O is the most unpredictable resource in a system. A decrease in IOPS will directly slow a job down, whereas changes to other attributes typically have the opposite effect. For example, a reduction in memory usage, CPU usage, or spilled data usually results in faster execution. |
|
28 |
max_peak_iops |
Maximum peak IOPS of the statement across all DNs. |
|
|
29 |
average_peak_iops |
Average peak IOPS of the statement across all DNs. |
|
|
30 |
iops_skew_percent |
I/O skew rate of the statement across DNs. |
|
|
31 |
query_plan |
Execution plan of the statement. |
G1: Check whether the job execution plan changes. |
|
32 |
unique_sql_id |
Used to identify a statement type. |
H1: If a specific type of SQL statement consumes excessive memory or CPU resources, you need to terminate it. You can add the statement to the blacklist using gs_append_blocklist(unique_sql_id int8) or gs_append_blocklist(sql_hash text). |
|
33 |
sql_hash |
||
|
34 |
enqueue |
Queue status of the statement. |
I1: Check whether the job is abnormally queued or queued for a long time. The following situations may occur:
|
|
35 |
warning |
Alarm information about statements and alarms related to SQL self-diagnosis and optimization. For details about common warning information, see Table 4. |
J1: The following alarms may occur:
|
Conclusion:
- The job is processing a much larger amount of data than before. You can analyze A2, B1, D1, and G1 to check whether there is a substantial increase in the data volume of the queried tables.
- Currently, the historical Top SQL views contains a large number of fields. You can view the PGXC_QUERY_INFO view to query the classic fields, instead of manually filtering out irrelevant fields.
- Competition for resources from other jobs is a frequent cause of slowdowns. For job queuing, you can analyze A1, B1, and D1 to check whether a large number of concurrent jobs are executed during the job execution.
- For CPU contention, you can analyze A2/D1/E1 to check whether a large number of concurrent jobs are being executed.
- For I/O contention, you can analyze A2/F1 to check whether a large number of concurrent jobs are being executed.
- A certain type of statements uses heavy resources. You can analyze H1 to prohibit their execution.
CPU contention, I/O contention, and job queuing may concurrently occur during resource contention. You can analyze and solve the issues step by step. For example:
- Adjust the job execution sequence, reduce the number of concurrent jobs, and reduce the blocking time.
- Identify and shift compute and storage-intensive jobs to off-peak periods to minimize contention with priority jobs.
- If no other jobs intervene, perform further analysis.
|
Scenario |
Warning |
Troubleshooting |
|---|---|---|
|
Excessive or premature disk flushing |
The max spill size exceeds the alarm size xxxMB |
Disk flushing may be caused by a small buffer, inefficient table joins, or a suboptimal join mode. Analyze and rewrite the SQL statement or use a plan hint to specify a better join way. |
|
The max broadcast size exceeds the alarm size xxxMB |
||
|
Early spill |
||
|
Spill times is greater than 3 |
||
|
Spill on memory adaptive |
||
|
Hash table conflict |
||
|
Statistics |
Nestloop in hashjoin |
The statistics may be inaccurate. Analyze the related service tables in a timely manner. |
|
Table whose delta data exceeds 10% cannot be analyzed on VW |
ANALYZE is unavailable in elastic VWs. |
|
|
Replication table cannot be analyzed on VW in temporary table sampling mode. |
||
|
Table cannot be analyzed on VW when enable_paralled_analyze is disabled in temporary table sampling mode. |
||
|
Replication table with more than 100,000 rows cannot be analyzed on VW. |
||
|
Elastic VWs |
Concurrent scaling is not supported because the statement is in a transation block. |
After elastic VW load balancing is enabled, jobs cannot be routed to elastic VWs. |
|
Concurrent scaling is not supported because the statement is a stored procedure. |
||
|
Concurrent scaling is not supported because the statement is not of the DML type. |
||
|
Concurrent scaling is not supported because the statement involves tables except V3 tables and foreign tables. |
||
|
Concurrent scaling is not supported because the statement does not support the cudesc streaming. |
||
|
Concurrent scaling is not supported because the resource pool associated with the statement disables the concurrency extension parameter. |
||
|
Concurrent scaling is not supported because the statement does not support cn retry. |
||
|
Materialized views |
has others update base table, can not active matview. |
An alarm is generated when a materialized view is refreshed. |
Notes and Constraints
- Top SQL does not record whitelisted and internal statements, but records statements delivered by superusers and scheduled tasks.
- The key difference between query and perf the query_plan field. query_plan provides operator-level details in query, but in perf, the field augments this with runtime statistics like actual memory usage, automatic memory expansion information, and CU/Buffers data.
- For query and perf levels, the start_time field represents the job delivery time in real-time top SQL, but the time that the job starts to run in historical top SQL.
- When querying the historical top SQL statements of the query, perf, and operator levels, you can only connect to the postgres database.
- Constraints on real-time top SQL statements:
- Special DDL statements, such as SET, RESET, SHOW, ALTER SESSION SET, and SET CONSTRAINTS, are not recorded.
- DDL statements, such as CREATE, ALTER, DROP, GRANT, REVOKE, and VACUUM, are recorded.
- DML statements are recorded, including:
- SELECT, INSERT, UPDATE, and DELETE
- EXPLAIN ANALYZE and EXPLAIN PERFORMANCE
- Views at the query or perf level
- The entry statements for invoking functions and stored procedures are recorded. When the GUC parameter enable_track_record_subsql is enabled, some internal statements (except the DECLARE definition statement) of a stored procedure can be recorded. Only the internal statements delivered to DNs for execution are recorded.
- The anonymous block statement is recorded. When the GUC parameter enable_track_record_subsql is enabled, some internal statements of an anonymous block can be recorded. Only the internal statements delivered to DNs for execution are recorded.
- The cursor statements are recorded. The system only records cursor statements that are executed on DNs. The statement and execution plan are enhanced. If a cursor's data is served from the cache, the statement is not recorded. Furthermore, a known architectural limitation prevents the recording of monitoring data for cursors inside functions or anonymous blocks that read large amounts of data from a DN but do not fully consume the result set. The With Hold cursor syntax has a special execution logic. It executes queries when a transaction is committed. If a statement execution error is reported, the aborted status of the job cannot be recorded in the Top SQL history table.
- Statistics are not collected for jobs in the redistribution process.
- For a statement with placeholders executed by JDBC, the parameter content is usually supplemented. However, if the total length of the parameter and the original statement exceeds 64 KB, the parameter is not recorded. Lightweight statements are directly delivered to the DNs for execution and their parameter are not recorded. If a common statement exceeds 64 KB, it will be truncated. For details, see the query field.
- In clusters of version 8.1.3 or later, the top SQL monitoring at the query and perf levels does not affect the query performance. The default value of resource_track_cost is 0. When you query the real-time monitoring views, all statements that are being executed are displayed by default.
- In clusters of version 8.1.3 or later, if enable_track_record_subsql is enabled, regardless of whether sub-statement monitoring is enabled in the service statements, you can view the sub-statement execution information in the real-time monitoring views.
- In clusters of version 8.1.3, statements cannot be filtered by time. Once enable_track_record_subsql is enabled, too many statements may be recorded and the archived monitoring table occupies a large amount of disk space. You are advised to enable only the parameters in specified sessions when querying real-time monitoring information or locating and analyzing some stored procedures. In clusters of version 8.2.1, you can use resource_track_subsql_duration to filter sub-statements to be archived based on the execution time. Its default value is 180 seconds and you can change the value as required.
- For a main statement that is not spilled to disks, its record in the top SQL history table is displayed only when the next job is delivered.
- In clusters of version 8.2.1.200 or later, you can enable operator_realtime-level monitoring to query the execution plan and detailed execution information of a statement. When you query the operator-realtime monitoring views of top SQL statements, all statements that are being executed are displayed by default. However, in stored procedure and cursor scenarios, operator-realtime monitoring information cannot be displayed.
- operator_realtime monitoring is not supported for lightweight CN statements and stored procedures. Operators are executed at a high speed, so there is a delay in displaying operator information.
- The spill_size field at the query level (job monitoring) and operator level (operator monitoring) varies due to the statistical dimension. The field indicates the statement files spilled to disks at the query level, while at the query level, it indicates the read and write I/O volume of a specific operator at the logical layer.
- When enable_stream_operator is set to off, the displayed operator execution information may be inaccurate.
- For clusters of version 8.1.3, except for the initial user, if enable_gtm_free is enabled and the joined queue is not controlled, user jobs are not managed in resource management. The system does not record the jobs delivered by the user in real-time or in historical top SQL statements.
Identifying Resource-Intensive SQL Statements Using Top SQL Monitoring
- Identify statements with a large number of streams.
SELECT *,(length(query_plan) - length(replace(query_plan, 'Streaming', ''))) / length('Streaming') AS stream_count FROM pgxc_wlm_session_info ORDER BY stream_count DESC limit 100;
- Identify statements with high memory usage.
SELECT * FROM pgxc_wlm_session_info WHERE start_time > 'xxxx-xx-xx' AND start_time < 'xxxx-xx-xx' ORDER BY max_peak_memory desc limit 100;
- Identify statements to be optimized.
SELECT * FROM pgxc_wlm_session_info WHERE start_time > 'xxxx-xx-xx' AND start_time < 'xxxx-xx-xx' AND warning is not null ORDER BY duration desc limit 100;
- Identify statements that take a long time to execute.
SELECT * FROM pgxc_wlm_session_info WHERE start_time > 'xxxx-xx-xx' AND start_time < 'xxxx-xx-xx' ORDER BY duration desc;
- Identify statements that cannot be pushed down.
SELECT * FROM pgxc_wlm_session_info WHERE start_time > 'xxxx-xx-xx' AND start_time < 'xxxx-xx-xx' AND warning like '%can not be shipped%' ORDER BY max_peak_memory desc;
- Identify statements with high CPU usage.
SELECT * FROM pgxc_wlm_session_info WHERE start_time > 'xxxx-xx-xx' AND start_time < 'xxxx-xx-xx' ORDER BY max_cpu_time desc;
- Identify statements with a large amount of data to be written to disks.
SELECT * FROM pgxc_wlm_session_info WHERE start_time > 'xxxx-xx-xx' AND start_time < 'xxxx-xx-xx' ORDER BY max_cpu_time desc;
- Identify the statements that are not analyzed.
SELECT * FROM pgxc_wlm_session_info WHERE start_time > 'xxxx-xx-xx' AND start_time < 'xxxx-xx-xx' AND warning ilike '%statistics%';
Monitoring PERT Job-Level Top SQL Statements
On the live network, an SQL statement that initially executes quickly may later experience slowdowns. To diagnose this, use the query_plan and resource data in top SQL statements. A detailed query_plan acts like an EXPLAIN PERFORMANCE and simplifies fault localization. The key difference between query-level and perf-level top SQL statements is the detail in the query_plan. Perf-level query_plan provides execution details for each operator, including actual time, memory usage, rows processed, and buffer activity, while query-level query_plan does not.
Monitoring OPERATOR Operator-Level Top SQL Statements
To monitor operator-level progress for long-running SQL statements, set resource_track_level to OPERATOR. This allows users to identify slow operators by their execution time and processed rows, and determine whether to kill the SQL statements.
Operator monitoring visualizes SQL execution data, providing an intuitive overview of operator status and performance. Its benefits include:
- Enhanced user experience: You gain an immediate, intuitive understanding of operator behavior and health.
- Streamlined performance tuning: You can quickly identify performance bottlenecks and inefficiencies within operators to optimize execution speed.
- Accelerated troubleshooting: You can detect runtime exceptions and problems in real-time, enabling faster remediation and improving overall SQL maintainability.
- Informed scalability planning: You can uncover and eliminate bottlenecks, increasing operator scalability for future business growth.
Operator monitoring is similar to query/perf statement monitoring. They both include real-time and historical information or static and dynamic information.
- Static statement information is generated by the optimizer before a statement is executed. The information includes node name of the execution plan, query ID, and estimated rows. You can use the information to analyze whether the generated execution plan is appropriate.
- Dynamic statement information refers to the resource information occupied during statement execution in the executor. The information includes the operator progress, peak memory, spill size, network size, disk I/O (read bytes and write bytes), and CPU time on each DN. You can use the information to analyze the progress and resource consumption during statement execution.
Example: Query the real-time operator view pgxc_wlm_operator_statistics in another session. The command output is as follows.

Interaction Between Top SQL Views and Other views
Different views collect statistics on the database status from different dimensions. As these views share common fields, they can be joined for further analysis. The following figure lists other views that are frequently work with historical top SQL views.
Example: The historical pgxc_wlm_session_info view shows that a statement is completed quickly, but the pgxc_stat_activity view shows that the statement has been executed for a long time. In this case, an exception may occur.
Perform the following steps to locate the fault:
- Query the pgxc_stat_activity view to find the abnormal jobs that have been running for a long time.
SELECT coorname, usename, client_addr, now()-query_start as dur, state, enqueue, waiting, pid, query_id, substr(query,1,150) FROM pgxc_stat_activity WHERE usename not in ('omm','Ruby') AND state = 'active' ORDER BY dur DESC limit 100; - Query the historical view using the information obtained in 1, and compare the statement's execution time before and after the fault. A marked increase in duration suggests an abnormal statement. The view is partitioned by day. You can use start_time to query the historical view.
SELECT * FROM pgxc_wlm_session_info WHERE start_time > '2024-08-22 00:00' AND start_time < '2024-08-24 00:00' AND query ilike '%XXXXXXXXX%' ORDER BY start_time;
- Query the pgxc_thread_wait_status view based on the query_id obtained in 1, obtain the job thread number lwtid, and print the job stack for analysis.
SELECT * FROM pgxc_thread_wait_status WHERE query_id = xxx; SELECT * FROM gs_stack('nodename',tid);
Analyzing and Handling Top SQL Cases
When there is a larger amount of information about top SQL statements, you can use start_time to target specific time ranges and LIMIT to constrain the result set. This prevents full-table scans and avoids client-side issues from excessive data.
- Case 1: The system-level performance of a customer's cluster is poor, the CPU usage keeps increasing, and services are affected.
The top SQL historical view shows that more than 10 QL statements have more than 100 streams. The CPU usage is high.
SELECT *,(length(query_plan) - length(replace(query_plan, 'Streaming', ''))) / length('Streaming') as stream_count FROM pgxc_wlm_session_info ORDER BY stream_count DESC limit 100;
Solution: Bring the SQL statement offline and optimize it.
- Case 2: A statement runs fast at first and then slows down.
Top SQL monitoring records statement execution and resource consumption to help you diagnose performance issues. For example, if a periodic SQL statement slows down, you can compare execution and block times to determine if it was queued or is genuinely slow. Analyze the execution plan to check for outdated statistics or missing ANALYZE operations. Check whether the slow performance is caused by a large amount of data spilled to disks.
- Check the historical SQL information in the pgxc_wlm_session_info view. (Note: The historical view is partitioned by day. When querying the view, add start_time.)
SELECT * FROM pgxc_wlm_session_info WHERE start_time > '2023-08-22 00:00' AND start_time < '2023-08-24 00:00' AND query ilike '%XXXXXXXXX%' ORDER BY start_time;
- Determine the historical execution status of jobs based on sql_hash, and analyze the job performance deterioration cause based on the resource information and query_plan field of historical top SQL statements.
SELECT start_time, block_time, duration, sql_hash, warning, max_peak_memory, max_spill_size, query_plan FROM pgxc_wlm_session_info were start_time > 'xxxx-xx-xx xx:xx' and sql_hash = 'xxx' ORDER BY start_time desc limit 10;
Compare the execution plans (query_plan) of the fast and slow statements. It is found that the execution plans change greatly.

- Perform ANALYZE on the corresponding table and choose a proper plan. After that, the statement performance is restored.
Outdated statistics often cause execution plan changes and slow queries. To prevent this issue, run ANALYZE, which doesn't affect read and write operations.
ANALYZE dwrdim_dw1.dwr_dim_region_rc_d;
- Check the historical SQL information in the pgxc_wlm_session_info view. (Note: The historical view is partitioned by day. When querying the view, add start_time.)
- Case 3: A job runs for a long time and does not end.
If a job is running without queuing or deadlock but is taking excessively long, you can use operator_realtime monitoring to pinpoint slow operators. Based on an operator's duration and processed rows, you can decide whether to kill the statement.
- Enable operator_realtime monitoring.
SET resource_track_level = 'operator_realtime';

- Kill the job as required.
SELECT * FROM pg_terminate_backend (xxx); #The input parameter is pid.
- Enable operator_realtime monitoring.
- Case 4: The overall memory usage of a job is high. You need to analyze the memory usage of operators.
When a job's overall memory usage is high, query-level monitoring cannot capture operator-level resource details. To resolve this, set the monitoring level to perf. This level records more granular execution data with a performance overhead of less than 5%. The query_plan field of perf-level monitoring can display operator time (actual time, memory, rows, and buffer).
- Enable perf-level monitoring.
SET resource_track_level = 'perf';
- After a job is executed, query the pgxc_wlm_session_info view to check the memory usage of each operator.

- Enable perf-level monitoring.
Feedback
Was this page helpful?
Provide feedbackThank you very much for your feedback. We will continue working to improve the documentation.See the reply and handling status in My Cloud VOC.
For any further questions, feel free to contact us through the chatbot.
Chatbot