Find queries executed in specific time range in Redshift

Article for: Snowflake Teradata Vertica

Query below shows queries executed in specific time range.

Notes

Table containing query log retain them approximately for 2-5 days then they are removed.

Query

Query below lists queries executed between 6 and 12 hours from current time.

select usename as username, 
       database, 
       querytxt as query, 
       starttime, 
       endtime, 
       case aborted
            when 1 then 'YES'
            else 'NO'
            end as aborted
from stl_query ql
join svl_user_info us 
     on ql.userid = us.usesysid
where starttime < DATEADD(hour, -6, getdate())
      and starttime > DATEADD(hour, -12, getdate())
order by starttime desc;

Columns

  • username - name of user who executed query
  • database - name of database in which query was executed
  • query - query text
  • starttime - start time of a query
  • endtime - end time of a query
  • aborted - indicate wheter query was aborted

Rows

  • One row represents one query executed in specifiic time range
  • Scope of rows: all queries executed in specifiic time range
  • Ordered by start time of query

Sample results

sample results

Comments are only visible when the visitor has consented to statistics cookies. To see and add comments please accept statistics cookies.
0
There are no comments. Click here to write the first comment.