在postgres中,如何知道每个模式哪个查询速度慢

问题描述 投票:0回答:1

我使用 postgres 模式进行多租户设置:

public
company_a
company_b

我需要查看哪些查询 x 公司很慢,可以直接使用 postgres 执行此操作吗?

P.D:另外,为了查看哪些值导致速度变慢,我只看到那里的参数:

SELECT
round(total_exec_time::numeric, 2) AS total_time,
calls,
round(mean_exec_time::numeric, 2) AS mean,
round((100 * total_exec_time /
sum(total_exec_time::numeric) OVER ())::numeric, 2) AS percentage_cpu,
query
FROM    pg_stat_statements
ORDER BY total_exec_time DESC
LIMIT 5;

-- query only show
UPDATE customer_sync SET customer_code = $1, address_co
postgresql query-optimization postgresql-15
1个回答
0
投票

在清晰的 ISO 标准 SQL 中,而不是在深奥的 PG 方言中,您可以找到运行与 SQL 模式关联的查询的用户:

SELECT CAST(total_exec_time AS numeric(16,2)) AS total_time,
       calls,
       CAST(mean_exec_time AS numeric (16,2)) AS mean,
       CAST(100.0 * total_exec_time / sum(total_exec_time) OVER () AS numeric(24,2) AS percentage_cpu,
       query,
       rolname
FROM   pg_stat_statements AS q
       INNER JOIN pg_authid AS a
          ON q.userid = a.oid
ORDER  BY total_exec_time DESC FETCH NEXT 5 ROWS ONLY;
© www.soinside.com 2019 - 2024. All rights reserved.