Book Image

Heroku Cookbook

By : Mike Coutermarsh
Book Image

Heroku Cookbook

By: Mike Coutermarsh

Overview of this book

Heroku is a Platform as a Service that enables developers to rapidly deploy and scale their web applications. Heroku is designed for developer happiness, freeing developers from doing system administrative tasks such as configuring servers and setting up load balancers. Developers are able to focus on what they do best, building web applications, while leaving the details of deployment and scaling to the experts at Heroku. This practical guide is packed with step-by-step solutions to problems faced by every production-level web application hosted on Heroku. You'll quickly get comfortable with managing your Heroku applications from the command line and then learn everything you need to know to deploy and administer production-level web applications.
Table of Contents (17 chapters)
Heroku Cookbook
Credits
About the Author
About the Reviewers
www.PacktPub.com
Preface
Index

Logging slow queries with PaperTrail


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.

Note

This recipe will only work with production-tier Heroku Postgres databases. The hobby-tier databases do not have logging enabled.

How to do it…

To start, let's open a terminal and navigate to our Heroku project that has the PaperTrail add-on. Then, perform the following...