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?
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
. 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.
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With