The first place where we'll usually experience application performance issues is in the database. A poorly written query or missing index can have a snowballing effect on our application's speed. As our application's traffic increases, detecting and fixing slow queries early on will help us avoid slow response times or even downtime.
Production-tier Heroku Postgres databases all come with logging capabilities. They are set up to send a log entry to Logplex whenever a query takes longer than 2 seconds to execute. We can use this to our advantage by setting up alerts to watch for these slow queries. In this recipe, we'll learn how to set up a search and an alert for slow queries using PaperTrail.