Real-time Top SQL

You can query real-time Top SQL in real-time resource monitoring views at different levels. The real-time resource monitoring view records the resource usage (including memory, data spilled to disks, and CPU time) and performance alarm information during job running.

The following table describes the external interfaces of the real-time views.

Table 1 Real-time resource monitoring views

Level

Monitored Node

View

Query level/perf level

Current CN

GS_WLM_SESSION_STATISTICS

All CNs

PGXC_WLM_SESSION_STATISTICS

operator level

Current CN

GS_WLM_OPERATOR_STATISTICS

All CNs

PGXC_WLM_OPERATOR_STATISTICS

Precautions

Prerequisites

In the preceding prerequisites, enable_resource_track is a system-level parameter that specifies whether to enable resource monitoring. resource_track_level is a session-level parameter. You can set the resource monitoring level of a session as needed. The following table describes the values of the two parameters.

Table 2 Setting the resource monitoring level to collect statistics

enable_resource_track

resource_track_level

Query-Level Information

Operator-Level Information

on(default)

none

Not collected

Not collected

query(default)

Collected

Not collected

perf

Collected

Not collected

operator

Collected

Collected

off

none/query/operator

Not collected

Not collected

Procedure

  1. Query for the real-time CPU information in the gs_session_cpu_statistics view.

    1
    SELECT * FROM gs_session_cpu_statistics;
    

  2. Query for the real-time memory information in the gs_session_memory_statistics view.

    1
    SELECT * FROM gs_session_memory_statistics;
    

  3. Query for the real-time resource information about the current CN in the gs_wlm_session_statistics view.

    1
    SELECT * FROM gs_wlm_session_statistics;
    

  4. Query for the real-time resource information about all CNs in the pgxc_wlm_session_statistics view.

    1
    SELECT * FROM pgxc_wlm_session_statistics;
    

  5. Query for the real-time resource information about job operators on the current CN in the gs_wlm_operator_statistics view.

    1
    SELECT * FROM gs_wlm_operator_statistics;
    

  6. Query for the real-time resource information about job operators on all CNs in the pgxc_wlm_operator_statistics view.

    1
    SELECT * FROM pgxc_wlm_operator_statistics;
    

  7. Query for the load management information about the jobs executed by the current user in the PG_SESSION_WLMSTAT view.

    1
    SELECT * FROM pg_session_wlmstat;
    

  8. Query the job execution status of the current user on each CN in the pgxc_wlm_workload_records view (this view is available when the dynamic load function is enabled, that is, enable_dynamic_workload is set to on).

    1
    SELECT * FROM pgxc_wlm_workload_records;