I'm over the GB limit on a postgres db on heroku.
I found a (very large) deprecated table and ran Plot.delete_all
. Now the 17k row table has 0 rows in it.
I can now see a difference in the row number but no difference in GB. Here's the Data Size before (37.73 GB)
heroku pg:info
=== HEROKU_POSTGRESQL_ONYX_URL, DATABASE_URL
Plan: Hobby-basic
Connections: 2/20
PG Version: 11.14
Created: 2019-03-09 12:13 UTC
Data Size: 37.73 GB/10.00 GB (Write access revoked; Database deletion imminent)
Tables: 6
Rows: 2649450/10000000 (In compliance)
Fork/Follow: Unsupported
Rollback: Unsupported
Continuous Protection: Off
Add-on: postgresql-spherical-39745
and after (still 37.73 GB, despite rows decreasing 16610):
heroku pg:info
=== HEROKU_POSTGRESQL_ONYX_URL, DATABASE_URL
Plan: Hobby-basic
Connections: 3/20
PG Version: 11.14
Created: 2019-03-09 12:13 UTC
Data Size: 37.73 GB/10.00 GB (Write access revoked; Database deletion imminent)
Tables: 6
Rows: 2649450/10000000 (In compliance)
Fork/Follow: Unsupported
Rollback: Unsupported
Continuous Protection: Off
Add-on: postgresql-spherical-39745
This Plot.delete_all
will delete all the rows in the plots table, but is it sufficient to free up the disk space that the db was occupying with those records?
What I've tried
heorku restart
made no difference.- I waited (60 minutes), but since heroku's background workers update these statistics typically no less frequently than every 5-10 minutes I presume that the readings are accurate and the bloat is still there
- I ran the postgress
CLUSTER
command, but I think it only performs operations on tables that have previously been clustered, so it completed quickly and didn't seem to do anything nor affect disk space) - I tried
VACCUM
but it finished quickly and didn't seem to affect disk space. - I tried
VACCUM FULL
- this took about 1-2 hours and worked! See results here.
Things I haven't tried yet, but may try
- I may edit the application code to remove the entire model, then
rake db:migrate
etc, and that should remove the unnecessary table entirely.