Created
January 9, 2015 17:38
-
-
Save deevis/7d675e1824ed845e1d2e to your computer and use it in GitHub Desktop.
MySQL Storage summary into Ruby Hash
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
db_name = Rails.configuration.database_configuration[Rails.env]["database"] | |
sql = "SELECT table_name AS name, table_rows, data_length, index_length FROM information_schema.TABLES WHERE table_schema = '#{db_name}' ORDER BY (data_length + index_length) DESC;" | |
table_data = ActiveRecord::Base.connection.execute(sql).map{|r| {name: r[0], rows: r[1], data_size: r[2], index_size: r[3]}} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment