Getting basic database table, size and count statistics

The task rake db:stats will print out basic database stats.

./launcher enter app
rake db:stats 

table_name                 | row_estimate | size
---------------------------------------------------
email_logs                 | 4027838      | 611 MB
post_timings               | 9193590      | 388 MB
posts                      | 285127       | 266 MB
post_search_data           | 285127       | 194 MB
topic_views                | 4177774      | 185 MB
optimized_images           | 683840       | 136 MB
topic_users                | 1450648      | 134 MB
topic_links                | 647432       | 111 MB
unsubscribe_keys           | 905960       | 109 MB
incoming_links             | 1828047      | 107 MB
notifications              | 404150       | 91 MB
topics                     | 142508       | 80 MB
topic_search_data          | 142913       | 72 MB
topic_link_clicks          | 1159317      | 70 MB
directory_items            | 701916       | 51 MB
user_actions               | 629565       | 46 MB
users                      | 116988       | 35 MB
user_visits                | 519360       | 26 MB
post_stats                 | 284715       | 19 MB
topic_allowed_users        | 245966       | 14 MB
post_revisions             | 17369        | 14 MB
uploads                    | 52288        | 14 MB
email_tokens               | 119044       | 13 MB
user_options               | 116988       | 12 MB
scheduler_stats            | 101012       | 12 MB
user_search_data           | 116988       | 12 MB
draft_sequences            | 219310       | 11 MB
user_stats                 | 116988       | 11 MB
group_users                | 144370       | 9632 kB
user_emails                | 116988       | 9104 kB
github_user_infos          | 113617       | 7808 kB
user_profiles              | 116988       | 7464 kB
user_avatars               | 116988       | 7144 kB
user_profile_views         | 129138       | 7000 kB
user_archived_messages     | 106711       | 6280 kB
post_actions               | 81849        | 6136 kB
user_badges                | 78525        | 5240 kB
user_auth_tokens           | 20396        | 5096 kB
user_histories             | 46810        | 4552 kB
top_topics                 | 18387        | 3136 kB
etc... 

You can use this to provide us some extra information about the size of your db when asking for help that may be related to db size.

11 Likes

how can we know (whole) database size?
While all db tables are there, whole DB size hasn’t been shown/told in this anywhere.

This is not Discourse specific, but you can run this to know the size of the whole database

./launcher enter app
rails db
SELECT pg_size_pretty(pg_database_size(current_database()));
2 Likes

Thank you.
I saw the db size successfully by this command.

But after that, in order to come out of Rails console decently, I pressed Ctrl+ z.
And it rather surprised me with this msg:

^Z[1]+  Stopped                 rails db

And then, when I pressed exit to come out, it said There are Stopped jobs and came to normal white prompt and thus I closed the window.

I’m rather afraid of these 2 msgs. Should I ?

Edit: My website seems to be working fine at this moment.