Getting Started: Monitoring a Heroku Postgres Database
Last updated May 09, 2023
Table of Contents
Heroku Postgres is a managed SQL database service provided directly by Heroku. You can access a Heroku Postgres database from any language with a PostgreSQL driver, including all languages officially supported by Heroku.
Heroku Postgres provides database and server metrics that give information on the status of your instance. Understanding and monitoring these metrics ensures the health of your database as your applications run and scale. Monitoring can also help you tune, debug, and troubleshoot your application. If you have a production database, make sure you’re monitoring it.
In this getting started, you learn how to:
- View the Postgres log
- Review monitoring add-on options
- Identify which database metrics to track
Before You Begin
You must have a Heroku Postgres database provisioned before you can proceed. Use the
heroku addons command to determine whether your app already has Heroku Postgres provisioned:
$ heroku addons Add-on Plan Price State ──────────────────────────────────────────── ───── ────── ─────── heroku-postgresql (postgresql-concave-52656) mini $5/month created
To learn how to create a Heroku Postgres database, see Provisioning Heroku Postgres.
Explore the Postgres Log
Heroku Postgres logs to the logplex which collates and publishes your application’s log-stream. You can isolate Heroku Postgres events with the
heroku logs command by filtering for the
$ heroku logs -p heroku-postgres -a heroku-101-demo-app 2022-04-21T07:46:55.000000+00:00 app[heroku-postgres]: source=HEROKU_POSTGRESQL_COBALT addon=postgresql-demo sample#current_transaction=509 sample#db_size=8426031bytes sample#tables=0 sample#active-connections=11 sample#waiting-connections=0 sample#index-cache-hit-rate=0 sample#table-cache-hit-rate=0 sample#load-avg-1m=0.02 sample#load-avg-5m=0.005 sample#load-avg-15m=0 sample#read-iops=0 sample#write-iops=0.10204 sample#tmp-disk-used=543600640 sample#tmp-disk-available=72435191808 sample#memory-total=3958708kB sample#memory-free=69612kB sample#memory-cached=3405616kB sample#memory-postgres=22080kB sample#wal-percentage-used=0.06428126026622091 ...
--tail option to access real-time log entries:
$ heroku logs -p heroku-postgres -a heroku-101-demo-app --tail
When you’re done, press Ctrl+C to return to the prompt. A real-time tail session automatically terminates after one hour of inactivity. Use the
-d) filtering argument to fetch logs with a certain source, a certain dyno, or both:
$ heroku logs --source my-application --dyno worker
If you don’t want to manually sift through logs, you can install a monitoring add-on.
Install a Monitoring Add-on
The most effective way to track database metrics is to install a platform monitoring add-on.
A full list of monitoring add-ons can be found on the Heroku Elements Marketplace. Many of these add-ons offer a free plan to get started. See your add-on’s documentation for instructions on retrieving logs.
Review Database Metrics
Heroku Postgres provides database and server metrics that give information on the status of your instance. Understanding and monitoring these metrics ensures the health of your database as your applications run and scale. Monitoring can also help you identify bottlenecks, bugs, and performance issues. You can look for these metrics in the log or in the dashboard for your monitoring add-on.
You can track metrics for the following:
- Database attributes apply to a particular database.
- Server come directly from the server operating system.
pg_bouncermetrics are included for any Heroku Postgres server that has a PgBouncer pooler attachment. These metrics are a subset of those viewable by running the
SHOW POOLS;command when connected to PgBouncer’s special internal database.
Learn more about monitoring Heroku Postgres databases with the following content: