How to I reset the statistics for a Heroku Postgres database?

Issue

I'd like to reset the pg_stats table to measure the performance of database changes.

Resolution

The pg_stat_statements are where Postgres records all kinds of performance information. This gets used in several Heroku commands including pg:diagnose, pg:outliers and pg:long-running-queries.

You can reset the pg_stat_statements directly in a psql console like so: heroku pg:psql <database> -a <app name> -c "SELECT pg_stat_statements_reset();".

Alternatively you can do this with Heroku PG extras plugin also:

heroku plugins:install heroku-pg-extras
heroku pg:stats-reset -a staktask-prod-1-backend