首页 > 解决方案 > 在 Redshift 中按总运行时间、执行时间、等待/排队时间列出排名靠前的查询?

问题描述

我知道亚马逊为 Redshift 提供了各种管理脚本,比如这个:

https://github.com/awslabs/amazon-redshift-utils/blob/master/src/AdminScripts/top_queries.sql

它按运行时列出了​​排名靠前的查询,我还发现这是类似的:

https://chartio.com/learn/amazon-redshift/identifying-slow-queries-in-redshift/

但是我想知道是否有一个类似于上述查询但除了执行时间之外还显示队列/等待时间的查询?

从这篇文章:

如何通过查询获得 redshift 中查询的总运行时间?

我收集到 stl_query 表包括执行时间 + 等待时间,但 stl_wlm_query 包括 total_exec_time,这只是执行时间。

更新:我有以下内容可以满足我的需求,但它似乎只返回最后一个月左右的数据,有什么想法可以获取旧数据吗?

    SELECT
w.userid,
w.query,
w.service_class_start_time AS "Day",
w.total_queue_time / 60000000 AS "Total Queue Time Minutes",
w.total_exec_time / 60000000 AS "Total Exec Time Minutes",
w.total_queue_time / 60000000 + w.total_exec_time / 60000000 AS "Total Time  Minutes"
FROM
stl_wlm_query w
ORDER BY
6 DESC

标签: sqlamazon-web-servicesamazon-redshift

解决方案


该查询正在使用该stl_wlm_query表。

来自用于日志记录的 STL 表 - Amazon Redshift

为了管理磁盘空间,STL 日志表仅保留大约两到五天的日志历史记录,具体取决于日志使用情况和可用磁盘空间。如果要保留日志数据,则需要定期将其复制到其他表或将其卸载到 Amazon S3。


推荐阅读