First you will need to have a log file. Please see this article, How To Download Query Log from Aura Instances, if you need information on how to get a query log. You can also view the documentation on logs for Aura.
Second, this code was tested on mac / linux, and uses the basic commands of grep and awk. However, no expertise is needed to run these commands. All you need is a downloaded log file, and a shell/terminal to execute the below commands. Assumes you are in the directory of the file called query.log, and will output a new file in that directory. Please see the examples below.
Example 1, filter out queries that take more than 1 second (1,000ms) from the file (query.log) in the current directory and into a file called slow_queries_extracted_1sec.log:
grep -i '"elapsedTimeMs"\|"query":' ./query.log | awk '/elapsedTimeMs/ {if ((substr($2,0,length($2)-1)+0)>1000) {print;getline;print;}}' > slow_queries_extracted_1sec.log
Example 2, filter out queries that take more than 30 seconds (30,000ms) from the file (query.log) and into a file called slow_queries_extracted_30sec.log:
grep -i '"elapsedTimeMs"\|"query":' ./query.log | awk '/elapsedTimeMs/ {if ((substr($2,0,length($2)-1)+0)>30000) {print;getline;print;}}' > slow_queries_extracted_30sec.log
Example 3, filter out queries that take more than 1 minute (60,000ms) from the file (query.log) and into a file called slow_queries_extracted_1min.log:
grep -i '"elapsedTimeMs"\|"query":' ./query.log | awk '/elapsedTimeMs/ {if ((substr($2,0,length($2)-1)+0)>60000) {print;getline;print;}}' > slow_queries_extracted_1min.log
Example 4, filter out queries that take more than 2 minutes (120,000ms) from the file (query.log) and into a file called slow_queries_extracted_2min.log:
grep -i '"elapsedTimeMs"\|"query":' ./query.log | awk '/elapsedTimeMs/ {if ((substr($2,0,length($2)-1)+0)>120000) {print;getline;print;}}' > slow_queries_extracted_2min.log
Comments
0 comments
Please sign in to leave a comment.