Heroku Postgres Metrics Logs
Last updated May 15, 2024
Table of Contents
Heroku Postgres Standard and Premium Tier database users see database-related events on their app’s log stream. These events are useful for recording and analyzing usage over time.
You can view your Postgres logs with the Heroku CLI, the dashboard, your logging add-on, or in your log drain. You can also install a platform monitoring add-on to help monitor these metrics.
Heroku Postgres metrics that appear via heroku-postgres
are separate from standard alerts emitted from Postgres itself that appear for all applications via postgres
.
For example, to get postgres
logs, run the command heroku logs -p postgres -a app-name
. To get heroku-postgres
logs, run the command heroku logs -p heroku-postgres -a app-name
.
Log Format
To view Heroku Postgres metrics logs on a specific app, use the process type -p heroku-postgres
flag and the app name.
$ heroku logs -p heroku-postgres -a example-app
For example, the Heroku Postgres metrics logs can look like:
2024-03-15T12:10:39.000000+00:00 app[heroku-postgres]: source=HEROKU_POSTGRESQL_SILVER addon=postgresql-devcenter-123456 sample#current_transaction=54017686 sample#db_size=16012956319bytes sample#tables=97 sample#active-connections=7 sample#waiting-connections=0 sample#index-cache-hit-rate=0.9239 sample#table-cache-hit-rate=0.93609 sample#load-avg-1m=0 sample#load-avg-5m=0 sample#load-avg-15m=0 sample#read-iops=0 sample#write-iops=0.13333 sample#tmp-disk-used=33849344 sample#tmp-disk-available=72944943104 sample#memory-total=4044960kB sample#memory-free=46920kB sample#memory-cached=3667532kB sample#memory-postgres=20824kB sample#wal-percentage-used=0.06512959334021144
The following attributes appear in application logs for all Standard and Premium-tier databases:
source
: The database attachment name that the measurements relate to, for example,HEROKU_POSTGRESQL_VIOLET
.- addon: The database addon name that the measurements relate to, for example,
postgres-metric-68904
. - The log line’s timestamp is the time at which the measurements were taken.
Database Metrics
Starting on May 15, 2024, we’ll begin gradually rolling out additional fields in database metrics.
These attributes apply to a particular database:
sample#db_size
: The number of bytes contained in the database. This metric includes all table and index data on disk, including database bloat.sample#tables
: The number of tables in the database.sample#active-connections
: The number of connections established on the database.sample#waiting-connections
: Number of connections waiting on a lock to be acquired. If many connections are waiting, this metric can be a sign of mishandled database concurrency.sample#current_transaction
: The current transaction ID, which can be used to track writes over time.sample#index-cache-hit-rate
: Ratio of index lookups served from shared buffer cache, rounded to five decimal points. Heroku recommends a value of 0.99 or greater if possible. If your index hit rate is consistently less than 0.99, investigate your Expensive Queries or upgrade your database plan for more RAM.sample#table-cache-hit-rate
: Ratio of table lookups served from shared buffer cache, rounded to five decimal points. Heroku recommends a value of 0.99 or greater if possible. If your table hit rate is consistently less than 0.99, upgrade your database plan for more RAM.sample#follower-lag-commits
: Replication lag, measured as the number of commits that this follower is behind its leader. Replication is asynchronous so a number greater than zero doesn’t indicate an issue, however an increasing value deserves investigation. Read more in Monitoring Followers. This metric is only published for follower databases.sample#primary-available
: For databases with high availability, a value of1
denotes database availability and a0
denotes database outage.sample#standby-available
: For databases with high availability, a value of1
denotes database availability and a0
denotes database outage.sample#service-available
: For databases without high availability, a value of1
denotes database availability and a0
denotes database outage.sample#rollback-from
: For databases that support rollback, the log either shows the timestamp of the earliest available rollback point orcapturing-snapshot
if the first backup is in progress.
Server Metrics
These metrics come directly from the server operating system:
sample#load-avg-1m
,sample#load-avg-5m
, andsample#load-avg-15m
: The average system load over a period of 1 minute, 5 minutes, and 15 minutes, divided by the number of available CPUs. Aload-avg
of 1.0 indicates that, on average, processes were requesting CPU resources for 100% of the timespan. This number includes I/O wait. For databases that have burstable performance, a baseline load average is guaranteed. For more information see the burstable performance section in the technical characteristic article.sample#read-iops
andsample#write-iops
: Number of read or write operations in I/O sizes of 16-KB blocks.sample#memory-total
: Total amount of server memory available.sample#memory-free
: Amount of free memory available in kB.sample#memory-cached
: Amount of memory being used by the OS for page cache, in kB.sample#memory-postgres
: Amount of memory being used by Postgres in kB.sample#tmp-disk-used
,sample#tmp-disk-available
: Number of bytes used and available on tmp mount.sample#wal-percentage-used
: Percentage of the WAL disk that has been used, between0.0
and1.0
. See this article for more details.
The operating system is designed to maximize the amount of memory it uses for its page cache, but can sometimes release that memory if an application requests it. For an estimate of the total amount of memory available to your server, add sample#memory-free
and sample#memory-cached
together.
PgBouncer Metrics
These metrics are included for any Heroku Postgres server that has a PgBouncer pooler attachment. These metrics are a subset of the metrics viewable by running the SHOW POOLS;
command when connected to PgBouncer’s special internal database:
sample#client_active
: The number of client connections to the pooler that have an active server connection assignment.sample#client_waiting
: The number of client connections to the pooler that are waiting for a server connection assignment.sample#server_active
: The number of server connections that are currently assigned to a client connection.sample#server_idle
: The number of server connections that aren’t currently assigned to a client connection.sample#max_wait
: The longest wait time of any client currently waiting for a server connection assignment.sample#avg_query
: The average query time of all queries executed through pooled connections.sample#avg_recv
: The number of bytes received from clients per second.sample#avg_sent
: The number of bytes sent to clients per second.