Hosting Operations
Read-only, sensitive outputShow MySQL Database Sizes
Disk usage is rising and you need to know which MySQL schemas are largest.
Command
mysql -e "select table_schema, round(sum(data_length + index_length)/1024/1024, 1) as mb from information_schema.tables group by table_schema order by mb desc;"
Before you run this
System impact: Read-only. Output may expose users, paths, tokens, keys, IPs, process arguments, or log details.
When not to use it: Do not use schema size alone to identify the exact table or index growth source.
Expected output
A sorted list of schema names and approximate size in MiB.
System impact
Read-only, sensitive output. Nothing changes. MySQL prints schema sizes.
Recovery / rollback: no state is changed.
When to use it
Use when storage alerts fire, backups grow, or migrations unexpectedly increase disk usage.
When not to use it
Do not use schema size alone to identify the exact table or index growth source.
Watch this command run
Command transcript
This sanitized transcript shows the commands and output shape without exposing host details.
$ df -h /var/lib/mysql
Filesystem Size Used Avail Use% Mounted on
/dev/vda1 25G 19G 5G 80% /work
$ mysql -e "select table_schema, round(sum(data_length + index_length)/1024/1024, 1) as mb from information_schema.tables group by table_schema order by mb desc;"
table_schema mb
shop 512.4
analytics 240.8
mysql 18.2
$ mysql -e "show databases;"
Database
analytics
information_schema
mysql
shop
View commands shown
These are the commands shown in the sanitized transcript.
Commands shown
df -h /var/lib/mysqlmysql -e "select table_schema, round(sum(data_length + index_length)/1024/1024, 1) as mb from information_schema.tables group by table_schema order by mb desc;"mysql -e "show databases;"
next steps
Related commands
Show PostgreSQL Database Sizes
Disk pressure starts with knowing what grew.
psql -X -c "select datname, pg_size_pretty(pg_database_size(datname)) as size from pg_database order by pg_database_size(datname) desc;"
Find Long-Running MySQL Queries
One old query explained the whole slowdown.
mysql -e "select id,user,host,db,command,time,state,left(info,80) as info from information_schema.processlist where command <> 'Sleep' order by time desc limit 10;"
Find Long-Running PostgreSQL Queries
One query can make the whole app look broken.
psql -X -c "select pid, now() - query_start as age, state, left(query, 80) as query from pg_stat_activity where query_start is not null order by age desc limit 10;"
Show Active PostgreSQL Connections
The database was not down. It was full.
psql -X -A -F '|' -c "select pid,usename,datname,state,client_addr from pg_stat_activity order by state, pid;"
Check PostgreSQL Lock Waits
The outage was a queue, not a crash.
psql -X -c "select pid, wait_event_type, wait_event, state, left(query, 80) as query from pg_stat_activity where wait_event_type is not null order by pid;"
Study mapping
Use this as independent command practice: read the notes, predict the output, then compare it with the example before using a real shell.
Useful for
- LPIC-1 style command-line practice
- LFCS style performance tasks
- Linux+ style troubleshooting review
Independent study support only. No affiliation, endorsement, exam dumps, or real exam questions.