Skip to content

Instantly share code, notes, and snippets.

@pcolazurdo
Created December 7, 2019 18:20
Show Gist options
  • Save pcolazurdo/d2dd6b0510ad5d80ba685cc711f503d9 to your computer and use it in GitHub Desktop.
Save pcolazurdo/d2dd6b0510ad5d80ba685cc711f503d9 to your computer and use it in GitHub Desktop.
Redshift: List frequency of key operations from stl_query

The following helps to analyze the frequency of each key operation.

  1. In Redshift run:
select * from stl_query where starttime::date='2019-12-05' and userid<>1 order by starttime,query;

and export it to stl_query.csv

  1. In bash, execute:
cat  stl_query.csv | cut  -f7 | sed -e 's/[[:space:]]*$//' | while read a
do
  echo $a | egrep -i -o 'select|delete|insert|copy|unload|vacuum|analyze|alter|create|drop' | head -1
done | tr '[:upper:]' '[:lower:]'| sort | uniq -c

Note: Key operation is defined as the first SQL DML/DDL command found in a SQL Statement

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment