Getting Started: Monitoring a Heroku Postgres Database
Last updated April 03, 2024
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 PostgreSQL logs
- Review monitoring add-on options
- Identify which database metrics to track
Logs are available on Standard-tier or higher databases. They aren’t available on Essential-tier databases.
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 Max Price State
─────────────────────────────────────────────────── ────────── ────────────────────────────── ────────────────────────────── ───────
heroku-postgresql (postgresql-elliptical-12345) standard-0 ~$0.069/hour $50/month created
To learn how to create a Heroku Postgres database, see Provisioning Heroku Postgres.
Explore Heroku Postgres Logs
You can view logs with the Heroku CLI, the dashboard, your logging add-on, or in your log drain.
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 postgres
process type with the -p flag.
Heroku Postgres metrics logs are emitted with heroku-postgres
as the process type:
$ heroku logs -p heroku-postgres -a example 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
...
PostgreSQL logs are emitted with the postgres
process type:
$ heroku logs -p postgres -a example app
2024-03-15T12:37:36.000000+00:00 app[postgres.2966211]: [DATABASE] [12-1] sql_error_code = 42703 (...)" application_name="psql interactive" ERROR: column "haiku" does not exist at character 8
...
Use the --tail
option to access real-time log entries:
$ heroku logs -p heroku-postgres -a example-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.
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_bouncer
metrics are included for any Heroku Postgres server that has a PgBouncer pooler attachment. These metrics are a subset of those viewable by running theSHOW POOLS;
command when connected to PgBouncer’s special internal database.
For more information about the different available metrics, see Heroku Postgres Metrics Logs. For a list of suggested metrics, see Monitoring Heroku Postgres.
Next Steps
Learn more about monitoring Heroku Postgres databases with the following content: