Skip to content

Instantly share code, notes, and snippets.

View wweidendorf's full-sized avatar

William Weidendorf wweidendorf

  • San Francisco, CA
View GitHub Profile
# Run rake db:size to get a print of your database size in bytes.
# Run rake db:tables:size to get the sizes for individual tables
# Works for MySQL and PostgreSQL. Not tested elsewhere.
namespace :db do
desc 'Print data size for entire database'
task :size => :environment do
database_name = ActiveRecord::Base.connection.instance_variable_get("@config")[:database]
adapter = ActiveRecord::Base.connection.adapter_name.downcase