PostgreSQL is one of the most popular open-source relational database systems. AWS offers services that make PostgreSQL database deployments easy to set up, manage, and scale in a cost-efficient manner. These services are Amazon Relational Database Service (Amazon RDS) for PostgreSQL and Amazon Aurora PostgreSQL-Compatible Edition.
Optimizing database performance is an important task for DevOps professionals. AWS provides tooling such as Amazon RDS Performance Insights and Amazon DevOps Guru for RDS to help with this task. The open-source community provides many options too, including the popular log analyzer pgBadger. pgBadger is an excellent tool for identifying both slow-running and frequently running queries and guiding you on how to improve their performance.
This GitHub repository contains:
- A set of AWS CloudFormation samples to deploy an Serverless infrastructure for enabling pgBadger report
- Code to build docker image for pgBadger
-
RDS PostgreSQL or Aurora PostgreSQL enabled with Cloudwatch logs.
-
RDS PostgreSQL or Aurora PostgreSQL enabled with correct logging parameters
-
Create ECR repository.
aws ecr create-repository --repository-name pgbadger-executor-py
-
Build and push docker image to ECR repository. this docker image will be used by Lambda function to process pgBadger logs.
-
Update Makefile in /app/badger-executor/py/badger-executor-py/Makefile with your account ID
-
Run Makefile
make
-
-
Amazon EC2 key pairs and Windows instances
aws ec2 create-key-pair --key-name MyKeyPair --output text > MyKeyPair.pem
-
(Optional) Run CloudFormation template
/inf/cfn/db.yml
to create Aurora Database in private VPC, following resources will be created.-
VPC
-
Private/Public subnet and related resources
-
Aurora DB in private subnet
NOTE: This step is not required if you are deploying solution for existing database in your VPC.
-
-
Run Cloudformation template
/inf/cfn/vpc-3az.yml
. This template will create brand new VPC and three private subnet to run Lambda and other resources. This cloudformation will also create Windows Server to access pgbadger report. -
Run Cloudformation template
/inf/cfn/pgbadger.yml
. Provide parent stack name from Step 2
Cloudformation output will give you link to URL for pgBadger Website, that will point to pgBadger report. report is setup up to run in auto-increment mode. DataSync is scheduled to run every hour, so report should update every hour. If you need to update report sooner then that, in that case you will have run DataSync task manually. Or you can duplicate the job in a different AZ.
- Open CloudFormation stack (
pgbadger.yml
), and checkOutputs
->PGbadgerWebsiteURL
to get PgBadger website URL. - Open CloudFormation stack (
vpc-3az.yml
), and checkOutputs
->{StackName}-EC2PublicIp
to get Windows ec2 Public IP address. - RDP to Windows VM, use the browser to access
PGbadgerWebsiteURL
url for pgbader reports.
This library is licensed under the Apache 2.0 License.