简体   繁体   English

按总运行时间,执行时间,等待/排队时间列出Redshift中的热门查询?

[英]List top queries by total runtime, execution time, wait/queue time in Redshift?

I know Amazon has provided various admin scripts for Redshift, such as this one: 我知道亚马逊已经为Redshift提供了各种管理脚本,例如:

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

which lists the top queries by runtime, and I also found this which is similar: 它按运行时列出了​​最热门的查询,我也发现了类似的内容:

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

however I'd like to know if there is a query which is similar to the above queries but also shows queue/wait time in addition to execution time? 但是我想知道是否有一个查询与上述查询类似,但除了执行时间外还显示队列/等待时间?

From this post: 从这篇文章:

How can I get the total run time of a query in redshift, with a query? 如何通过查询获得redshift中查询的总运行时间?

I gather that the stl_query table includes the execution time + wait time, but that the stl_wlm_query includes the total_exec_time, which is just the execution time. 我收集到stl_query表包括执行时间+等待时间,但是stl_wlm_query包括total_exec_time,这只是执行时间。

Update: I've got the following which gives me what I want, but it seems to only return the last month or so of data, any ideas how I get older data? 更新:我有以下内容可以满足我的要求,但似乎只返回上个月左右的数据,对我如何获得旧数据有任何想法吗?

    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

That query is using the stl_wlm_query table. 该查询正在使用stl_wlm_query表。

From STL Tables for Logging - Amazon Redshift : 用于日志记录的STL表-Amazon Redshift

To manage disk space, the STL log tables only retain approximately two to five days of log history , depending on log usage and available disk space. 为了管理磁盘空间,STL日志表仅保留大约两到五天的日志历史记录 ,具体取决于日志使用情况和可用磁盘空间。 If you want to retain the log data, you will need to periodically copy it to other tables or unload it to Amazon S3. 如果要保留日志数据,则需要定期将其复制到其他表或将其卸载到Amazon S3。

The following query will list top queries by execution time, but as John mentions above, will only return two to five days of log history. 下面的查询将按执行时间列出最热门的查询,但正如John上面提到的,只会返回两到五天的日志历史记录。

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM