Posted about 1 month ago. Visible to the public.

Checking database size by row count

As an application exists, data accumulates. While you'll be loosely monitoring the main models' record count, some supportive database tables may grow unnoticed.

To get a quick overview of database table sizes, you can view the row count like this:

Copy
# PostgreSQL SELECT schemaname,relname,n_live_tup FROM pg_stat_user_tables ORDER BY n_live_tup DESC; schemaname | relname | n_live_tup ------------+------------------------------------------------+------------ public | images | 17025 public | items | 16918 public | tree_nodes | 5018 public | page_versions | 4049 public | pages | 3919
Copy
# MySQL SELECT table_name, table_rows FROM information_schema.tables WHERE table_schema = (SELECT database()) ORDER BY table_rows DESC; +---------------------+------------+ | table_name | table_rows | +---------------------+------------+ | addresses | 48106 | | orders | 33740 | | users | 8703 | | ...

If you're interested in the space a table takes up on the disk check table sizes by disk usage instead.

Growing Rails Applications in Practice
Check out our new e-book:
Learn to structure large Ruby on Rails codebases with the tools you already know and love.

Owner of this card:

Avatar
Dominik Schöler
Last edit:
26 days ago
by Dominik Schöler
About this deck:
We are makandra and do test-driven, agile Ruby on Rails software development.
License for source code
Posted by Dominik Schöler to makandra dev
This website uses cookies to improve usability and analyze traffic.
Accept or learn more