Search code examples
herokuheroku-postgres

Phantom rows in table


My hobby plan database is currently over the 10,000 row limit, which is confusing to me because I have an hourly scheduled job that clears out old rows well in advance.

The psql-extras toolbelt reports this:

heroku pg:index_usage -a my-app
    relname     | percent_of_times_index_used | rows_in_table 
----------------+-----------------------------+---------------
 table_one      | 26                          |          8710
 table_two      | Insufficient data           |          1235
 table_three    | 73                          |           637
 table_four     | 0                           |           429
 table_five     |                             |             1
(5 rows)

So that's over the limit... however when I SELECT COUNT(*) the rows in each table (which is what my scheduled job does), I can only find about 8,000 rows.

Take table_one, for example:

$ heroku psql -a my-app
--> Connecting to postgresql-my-db
psql (11.1, server 9.6.11)
SSL connection (protocol: TLSv1.2, ...)
Type "help" for help.

my-app::DATABASE=> SELECT COUNT(*) FROM table_one;
 count 
-------
  5708
(1 row)

Does anyone know where these 3,000 extra rows are coming from?

Many thanks in advance.


Solution

  • An AUTOVACUUM seems to have sorted it out. Not sure why this happened after the thing has been running fine for over a year, but never mind.