简体   繁体   English

Redshift表 - 查找表的查询的最后日期

[英]Redshift Table - Find Last Date of Query on a Table

I am trying to clean up my small database and trying to see when the last time some of the tables were actually queried but cannot seem to find any documentation on how to do this. 我正在尝试清理我的小型数据库,并试图查看上次实际查询某些表的时间,但似乎无法找到有关如何执行此操作的任何文档。 I can get the listing of all of the tables in my schema and the sizes, but cannot identify what might be stale before polling my users. 我可以获取我的架构中的所有表的列表和大小,但在轮询我的用户之前无法识别可能过时的内容。

Does anyone know of a way to get the last date that a table was used/queried in redshift? 有没有人知道如何获得在redshift中使用/查询表的最后日期?

select
    schema,  
    "table",
     size as GB
from svv_table_info
    where schema = 'measure' or schema = 'mphd' or schema = 'offer'
order by schema asc;

You can see when the table was last scanned in stl_scan . 您可以在stl_scan查看上次扫描表的stl_scan Almost all select queries will scan. 几乎所有选择的查询都会扫描。 The following is taken from: https://github.com/awslabs/amazon-redshift-utils/blob/master/src/AdminViews/v_extended_table_info.sql As you've noted the history is only held for a limited period. 以下内容摘自: https//github.com/awslabs/amazon-redshift-utils/blob/master/src/AdminViews/v_extended_table_info.sql正如您所知,历史记录仅在有限的时间内举行。

SELECT tbl,
       MAX(endtime) last_scan,
       Nvl(COUNT(DISTINCT query || LPAD(segment,3,'0')),0) num_scans
FROM stl_scan s
WHERE s.userid > 1
AND   s.tbl IN (SELECT oid FROM tbl_ids)
GROUP BY tbl

You will quite possible have to parse entries in STL_QUERYTEXT , which stores SQL queries. 您很可能必须解析存储SQL查询的STL_QUERYTEXT条目。

It might be easier to parse STL_EXPLAIN . 解析STL_EXPLAIN可能更容易。

Both of these tables can be joined back to STL_QUERY to obtain a time when the query was executed. 这两个表都可以连接回STL_QUERY以获取执行查询的时间。

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

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