From 4c6a0313f235ee0cb12e546725586c35c63063e4 Mon Sep 17 00:00:00 2001 From: Sam Saffron Date: Fri, 2 Aug 2019 17:25:30 +1000 Subject: [PATCH] FEATURE: improve stats provided by rake db:stats New stats include index size and sort by index + table size Eg: ``` table_name | row_estimate | table_size | index_size | total_size -------------------------------------------------------------------------- topic_views | 18260776 | 796 MB | 2015 MB | 2811 MB post_timings | 15813837 | 668 MB | 1153 MB | 1821 MB posts | 386890 | 1532 MB | 215 MB | 1747 MB post_search_data | 317575 | 580 MB | 162 MB | 742 MB incoming_emails | 34412 | 734 MB | 7160 kB | 741 MB incoming_links | 5169302 | 306 MB | 377 MB | 683 MB email_logs | 5 | 32 kB | 418 MB | 418 MB topic_users | 2410166 | 217 MB | 155 MB | 372 MB user_actions | 1361253 | 101 MB | 266 MB | 366 MB ... ``` --- lib/tasks/db.rake | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/lib/tasks/db.rake b/lib/tasks/db.rake index 61975adef62..afc470f4f4b 100644 --- a/lib/tasks/db.rake +++ b/lib/tasks/db.rake @@ -119,10 +119,12 @@ task 'db:stats' => 'environment' do from pg_class where oid = ('public.' || table_name)::regclass ) AS row_estimate, - pg_size_pretty(pg_relation_size(quote_ident(table_name))) size + pg_size_pretty(pg_table_size(quote_ident(table_name))) table_size, + pg_size_pretty(pg_indexes_size(quote_ident(table_name))) index_size, + pg_size_pretty(pg_total_relation_size(quote_ident(table_name))) total_size from information_schema.tables where table_schema = 'public' - order by pg_relation_size(quote_ident(table_name)) DESC + order by pg_total_relation_size(quote_ident(table_name)) DESC SQL puts