Last active
October 31, 2023 16:13
-
-
Save voxxit/d1e4b4e8240ad3174d0f to your computer and use it in GitHub Desktop.
Downloads RDS slow query logs for the last 24 hours using the AWS CLI
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
instanceID=$1 | |
date=$(date +%Y%m%d) | |
function downloadLog () { | |
local log=$1 | |
aws rds download-db-log-file-portion \ | |
--output text \ | |
--db-instance-identifier $instanceID \ | |
--log-file-name $log | |
} | |
downloadLog slowquery/mysql-slowquery.log > slow-$date.log | |
for i in $(seq 0 23); do | |
downloadLog slowquery/mysql-slowquery.log.$i >> slow-$date.log | |
done | |
# Runs pt-query-digest from the Percona toolkit, if found | |
if which pt-query-digest >/dev/null; then | |
pt-query-digest slow-$date.log > slow-digest-$date.log | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This one worked for me:
usage :
./download-slow-query-log.sh my-db-1 '2020-07-18'