I need to work out how many rows a database has in total in order to stay under a cap which, if exceeded, will result in a hosting providing deleting the db!.
ActiveRecord::Base.connection.tables
=> ["ar_internal_metadata", "listings", "metrics", "plots",
"schema_migrations", "packages"]
and add the number of rows in each table:
irb(main):016:0> ArInternalMetadata.count
Traceback (most recent call last):
1: from (irb):16
NameError (uninitialized constant ArInternalMetadata)
irb(main):017:0> Listing.count
=> 7940328
irb(main):018:0> Metric.count
=> 17016
irb(main):019:0> Plot.count
=> 17016
irb(main):020:0> SchemaMigration.count
Traceback (most recent call last):
1: from (irb):20
NameError (uninitialized constant SchemaMigration)
irb(main):021:0> Package.count
=> 18798
7940328 + 17016 + 17016 + 18798 = 7993158
The hosting provider will delete the database in 7 days because it exceeds their usage cap, which is 10,000,000 rows.
Presuming ar_internal_metadata and schema_migrations aren't massive, then I think there's ~8m rows and Heroku thinks there >10m.
Question
How can I (accurately) count how many rows a rails (postgres) database has?