If the number of CPU wait events is large for a consecutive period, a CPU bottleneck occurs. In this case, you must check the relevant data and analyze this issue.
SELECT
backend_type,SUM(cpu_sys cpu_user) AS cpu_rate
FROM polar_stat_activity_rt
GROUP BY backend_type
ORDER BY cpu_rate desc; \watch 1
If the number of CPU wait events is greater than the number of CPU cores for a consecutive
period, the number of concurrent CPU wait events is large. SELECT
query, COUNT(*) AS wait_count
FROM polar_stat_activity
WHERE state='active' AND backend_type='client backend' AND wait_event_type IS NULL
GROUP BY query
ORDER BY wait_count DESC; \watch 1
Check the increments of the values in the xact_commit and xact_rollback columns in the pg_stat_database view to determine whether the number of transactions per second (TPS) meets your business requirements. You can also check the increment of the total number of executed queries in the polar_stat_query_count view to determine whether the number of queries per second meets your business requirements.
After you identify the SQL statements that cause high CPU utilization, you can obtain the SQL statistics from the pg_stat_statements and polar_stat_sql views.