Last active
November 7, 2023 16:03
-
-
Save rubikill/4d0aa9849fe5a13ef8fa0f32f99dca0f to your computer and use it in GitHub Desktop.
Build psql report RDS using pgbadger
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
# sh export_log.sh db_identifier | |
# If any of this commands fail, stop script. | |
set -e | |
db_identifier=$1 | |
date=$(date -v-7H +'%Y-%m-%d-%H') | |
log_file=~/Desktop/postgresql.log.$date | |
report_file=~/Desktop/out.$date.html | |
page_size=100000 | |
aws rds download-db-log-file-portion --db-instance-identifier $db_identifier --log-file-name error/postgresql.log.$date --page-size $page_size --output text > $log_file | |
~/Downloads/pgbadger-master/pgbadger -f rds $log_file -o $report_file -p '%t:%r:%u@%d:[%p]:' -f stderr -j 8 | |
echo $report_file |
DATE=2023-11-06-07
PROFILE=sample
DB_INSTANCE_IDENTIFIER=sample
LOG_FILE_NAME=error/postgresql.log.$DATE
LOG_FILE=~/Desktop/postgresql.log.$DATE
aws rds download-db-log-file-portion \
--profile $PROFILE \
--db-instance-identifier $DB_INSTANCE_IDENTIFIER \
--log-file-name $LOG_FILE_NAME \
--starting-token 0 \
--output text > $LOG_FILE
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Filter write queries