How to find number of rows in heroku database How to find number of rows in heroku database database database

How to find number of rows in heroku database


If you have the heroku cli tool, this will give you, among other things, the number of rows in your database

heroku pg:info -a your_app

Also given are your plan type, the db status, the number of current connections, postgres version, when the db was created, the number of rows in your plan, the data size, the number of tables and if your db has any fork/follow options activated.


This will give you the approximate count of all rows within your database:

 SELECT sum(reltuples) from pg_class where relname IN (SELECT c.relname FROM pg_catalog.pg_class c LEFT JOIN pg_catalog.pg_namespace n ON n.oid = c.relnamespace WHERE c.relkind = 'r' AND n.nspname <> 'pg_catalog' AND n.nspname <> 'information_schema' AND n.nspname !~ '^pg_toast' AND pg_catalog.pg_table_is_visible(c.oid));

Though the error message indicates some error on your database, likely a constraint violation versus something with your insert privileges being revoked.


Heroku released a "pg-extras" toolbelt which can give you extra informations like the number of rows of your database.

Even if you have a higher plan than Hobby, you will get the number of rows by doing the following:

heroku plugins:install heroku-pg-extras

Then:

heroku pg:index_usage --app dashboard

This will give you the number of rows per table.