InActive Redshift表

时间:2016-10-31 17:11:13

标签: amazon-redshift

Time-to-Time redshift用户为其计算目的创建持久临时表。这很好,但是这样的短期表会在一段时间内堆积起来并且不会向我们的仓库传达任何意义。     是否有任何redshift SQL或redshift方法来确定上次访问表的时间(选择,插入,删除,加载,卸载)。根据时间安排,我们可以向用户发出警告并放弃。

1 个答案:

答案 0 :(得分:0)

STL_QUERYSQL_QUERYTEXT表包含有关在Amazon Redshift上运行的查询的信息。

select query, substring(text,1,60)
from stl_querytext
where pid = pg_backend_pid()
order by query desc;

 query |                         substring
-------+--------------------------------------------------------------
 28262 | select query, substring(text,1,80) from stl_querytext where 
 28252 | select query, substring(path,0,80) as path from stl_unload_l
 28248 | copy category from 's3://dw-tickit/manifest/category/1030_ma
 28247 | Count rows in target table
 28245 | unload ('select * from category') to 's3://dw-tickit/manifes
 28240 | select query, substring(text,1,40) from stl_querytext where 
(6 rows)

您可以将这些查询分析为确定最近查询过哪些表,然后将它们与SVV_TABLEINFO进行比较,以确定最近使用了哪些表

您还应该鼓励用户使用CREATE TEMP TABLE,这会创建一个在sessio 结束时自动删除的表格。您可以使用权限强制某些用户组仅在自己的架构中创建TEMP表或表。