How much disk space does your Rails Database use?
Sunday, October 14th, 2007The other day I was asked how much disk space a particular Kete project’s production database used. I didn’t have an answer, so I started searching for one.
In my case, the db software is MySQL and getting a report about various aspects of a db’s tables boils down to this query:
The output of this query has way more information than I need, plus to get the total number of bytes used you have to add all the values up anyway, so I decided to make a rake task to make this repeatable and return something succinct.
I have added the new rake task to the Kete app’s codebase. If you aren’t a Kete user, but need this functionality for your Ruby on Rails app, you can find it here:
http://svn.kete.net.nz/projects/kete/trunk/lib/tasks/db-disk-usage-report.rake
Note there is a formatting method taken from the Rails Helpers, I would love to not duplicate this definition. If anyone has a recommendation for the best way to pull this method into this rake task, I would appreciate it. Probably a simple include statement, but I didn’t get around to figuring out the correct incantation.
I would also love to hear how best to make this handle other database software, for example PostgreSQL, too.
Cheers,
Walter