Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to find number of rows in heroku database

The title pretty much sums up my question, but here are more details:

I'm running a script to import rows into a heroku database. I started getting errors:

<class 'django.db.utils.DatabaseError'> current transaction is aborted, commands ignored until end of transaction block` 

The script runs smoothly on my localhost so I'm not looking for problems there. I recently received an email from heroku stating that I'm "Approaching row limit for dev database"

I'm assuming I hit the row limit but I'd like to confirm this before taking further action.

Does anyone know how I can find my current row count for the whole database? (I know I can just do a count on each table but I'm hoping there's a cleaner way)

like image 968
mea36 Avatar asked Sep 14 '12 22:09

mea36


People also ask

How can I see rows in Heroku?

"You could run heroku pg:psql to fire up a Postgres console, then issue \d to see all tables, and \d tablename to see details for a particular table." You can also type select * from tablename; to view the table contents.

How do I check my Heroku database?

You can find them by visiting the Resources tab on your Dashboard then clicking on the DB you use. It will take you to the Addons page in another tab. Click on the Settings tab then View Credentials. Using these credentials, you can use Adminer to login to the DB.

What is row limit in Heroku?

The Heroku Postgres dev plan will be limited to 10,000 rows.

How can I see my table in Heroku Postgres?

From the application dashboard on Heroku, go to the 'resources' tab and search for postgres. Provision it and use the free option. There's now a clickable link to the Datastore associated with your application. Go ahead and open the link to your datastore, and take note of exactly how to get here again.


2 Answers

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.

like image 60
GregB Avatar answered Sep 28 '22 02:09

GregB


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.

like image 44
CraigKerstiens Avatar answered Sep 28 '22 02:09

CraigKerstiens