haseebmirza / laravel-db-size
Artisan command to show database table sizes, row counts, and index sizes
Requires
- php: ^8.1
- illuminate/console: ^10.0|^11.0|^12.0|^13.0
- illuminate/database: ^10.0|^11.0|^12.0|^13.0
- illuminate/support: ^10.0|^11.0|^12.0|^13.0
Requires (Dev)
- orchestra/testbench: ^8.0|^9.0|^10.0|^11.0
- phpunit/phpunit: ^10.0|^11.0
README
Instant DBA overview without opening TablePlus or running raw SQL.
A single Artisan command that shows every table in your database with row counts, data size, index size, and total size — sorted biggest-first. Works with MySQL, PostgreSQL, and SQLite. Zero config.
php artisan db:size
INFO Database: my_app (mysql)
+--------------------+--------+-----------+------------+-----------+
| Table | Rows | Data Size | Index Size | Total |
+--------------------+--------+-----------+------------+-----------+
| activity_log | 84,231 | 42.5 MB | 12.3 MB | 54.8 MB |
| users | 3,402 | 1.2 MB | 0.8 MB | 2.0 MB |
| password_resets | 12 | 16 KB | 16 KB | 32 KB |
| migrations | 47 | 8 KB | 8 KB | 16 KB |
+--------------------+--------+-----------+------------+-----------+
| Total | 87,692 | 43.7 MB | 13.1 MB | 56.8 MB |
+--------------------+--------+-----------+------------+-----------+
Why?
- After a production alert — instantly see which table exploded
- Before a migration — know what you're working with
- During code review — "how big is that table anyway?"
- Onboarding — new devs get a feel for the data shape in seconds
No more googling information_schema queries. No more opening a GUI. Just one command.
Installation
composer require haseebmirza/laravel-db-size --dev
Auto-discovered. No config to publish. No migrations.
Usage
php artisan db:size
Options
| Flag | Description | Default |
|---|---|---|
--connection |
Database connection to use | Default connection |
--sort |
Sort by: total, data, index, rows, name |
total |
--asc |
Sort ascending | Descending |
--json |
Output as JSON | Table format |
Examples
# Check a specific connection php artisan db:size --connection=mysql # Sort by row count php artisan db:size --sort=rows # Alphabetical order php artisan db:size --sort=name --asc # Pipe JSON to jq or save to file php artisan db:size --json | jq '.[0]'
Supported Databases
| Driver | Row Count | Data Size | Index Size |
|---|---|---|---|
| MySQL / MariaDB | Exact | Exact | Exact |
| PostgreSQL | Estimated | Exact | Exact |
| SQLite | Exact | Via dbstat | N/A |
Requirements
- PHP 8.1+
- Laravel 10, 11, 12, or 13
Testing
composer test
Contributing
Contributions are welcome! Please feel free to submit a Pull Request.
License
The MIT License (MIT). Please see License File for more information.
Keywords: laravel database size, table size, row count, disk usage, mysql table size, postgres table size, sqlite size, database storage, artisan command, laravel devtools, database inspector, table stats, index size, database overview, laravel dba