Skip to content

Instantly share code, notes, and snippets.

@arthurchui
arthurchui / datasize.rake
Created August 19, 2022 22:17 — forked from shinzui/datasize.rake
Rake task to get database and table sizes.
# 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