title: Where can I find usage statistics in Redshift?
body: <p>Before all thank you for your help!</p>
  
  <p>I want to find out which tables in the database are most heavily used, i.e. the amount of users that query the table, the amount of times it was queried, the resources that where consumed by users per table, the total time the tables where queried, and any other useful data.
  For now I would limit the analysis to 9 specific tables.
  I'd tried using <strong>stl_scan</strong> and <strong>pg_user</strong> using the next two querys:</p>
  
  <pre><code>SELECT
      s.perm_table_name           AS table_name,
      count(*)                    AS qty_query,
      count(DISTINCT s.userid)    AS qty_users
  FROM stl_scan s
  JOIN pg_user b
      ON s.userid = b.usesysid
  JOIN temp_mone_tables tmt
      ON tmt.table_id = s.tbl AND tmt.table = s.perm_table_name
  WHERE s.userid &gt; 1
  GROUP BY 1
  ORDER BY 1;
  
  SELECT
      b.usename                                       AS user_name,
      count(*)                                        AS qty_scans,
      count(DISTINCT s.tbl)                           AS qty_tables,
      count(DISTINCT trunc(starttime))                AS qty_days
  FROM stl_scan s
  JOIN pg_user b
      ON s.userid = b.usesysid
  JOIN temp_mone_tables tmt
      ON tmt.table_id = s.tbl AND tmt.table = s.perm_table_name
  WHERE s.userid &gt; 1
  GROUP BY 1
  ORDER BY 1;
  </code></pre>
  
  <p>The <strong>temp_mone_tables</strong> is a temporal table that contains the id and name of the tables I'm interested.</p>
  
  <p>With this queries I'm able to get some information but I need more details. Surprisingly there's not much data online about this kind of statistics.</p>
  
  <p>Again thank you all beforehand!</p>