John
John

Reputation: 3460

Why does Heroku show more rows in DB after transfer?

I'm in the process of upgrading from the Heroku Bamboo stack to the Cedar stack. I'm following these instructions for the upgrade and these instructions for doing the Postgres transfers.

I took a snapshot of DB_1, and then did a restore of it to DB_2. Then, to check that everything went well, I ran heroku pg:info on both apps, and it showed that DB_1 has 7494 rows, while DB_2 has 7772 rows.

Why are there nearly 300 more rows in DB_2, even though it was a direct copy of the data from DB_1 with no changes?

I tried heroku restart but the condition remains. According to pg:info DB_1 is running Postgres 9.1.9 and DB_2 is running Postgres 9.2.4, I don't know if that makes a difference.

I also tried running this SQL query, and it also reported a different number of rows in DB_1 from DB_2:

 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))

Upvotes: 1

Views: 337

Answers (1)

Craig Ringer
Craig Ringer

Reputation: 324761

Heroku is probably using statistical sampling from the PostgreSQL pg_stat tables to estimate row counts, so it won't be an exact match for the databases's current exact rowcount.

An ANALYZE, possibly after increasing default_statistics_target, might change the reported results.

Upvotes: 3

Related Questions