Skip to main content

wp db size

Overview

Show how much disk space the WordPress database uses — either the total DB size or broken down by individual tables. The go-to command for spotting database bloat before it causes performance problems.

What It Does

wp db size queries information_schema to report the size (data + index) of the WordPress database. You can view data at the database level or per table, in human-readable or machine-readable formats.

Syntax

wp db size [--size_format=<format>] [--tables] [--format=<format>] [--scope=<scope>]

Options & Flags

FlagDefaultDescription
--size_format=FORMATb (bytes)Unit: b (bytes), kb, mb, gb
--tablesShow size for each table individually
--format=FORMATtableOutput format: table, json, csv, yaml
--scope=SCOPEallFilter scope: all, global, blog, old
--human-readableShow sizes in human-readable format

Basic Usage

Total database size

wp db size

Output:

+------------+------------+
| Name | Size |
+------------+------------+
| wordpress | 45,678,912 |
+------------+------------+

Human-readable total

wp db size --size_format=mb

Output:

+------------+--------+
| Name | Size |
+------------+--------+
| wordpress | 43.56 |
+------------+--------+

Size by table

wp db size --tables --size_format=mb

Output (truncated):

+---------------------+--------+
| Name | Size |
+---------------------+--------+
| wp_options | 18.23 |
| wp_postmeta | 9.45 |
| wp_posts | 6.12 |
| wp_redirection_logs | 4.87 |
| wp_comments | 1.23 |
+---------------------+--------+

Real-World Scenarios

Scenario 1: Identify top 5 largest tables

wp db size --tables --size_format=mb --format=csv | sort -t',' -k2 -rn | head -6

Scenario 2: Monitor DB size in a script

DB_SIZE=$(wp db size --size_format=mb --format=csv | tail -1 | cut -d',' -f2)
echo "Database size: ${DB_SIZE} MB"

if (( $(echo "${DB_SIZE} > 500" | bc -l) )); then
echo "WARNING: Database exceeds 500 MB — consider optimization"
fi

Scenario 3: Pre and post optimization comparison

echo "Before optimization:"
wp db size --size_format=mb

wp db optimize

echo "After optimization:"
wp db size --size_format=mb

Scenario 4: Report per-table sizes for client audit

wp db size --tables --size_format=mb --format=csv > db_size_report_$(date +%Y%m%d).csv
cat db_size_report_$(date +%Y%m%d).csv

Common Bloat Causes

TableCommon Cause of Bloat
wp_optionsPlugins storing data with autoload=yes; transients not cleaned
wp_postmetaOrphaned post meta; page builders storing large JSON
wp_redirection_logsRedirection plugin logs not rotated
wp_woocommerce_sessionsCustomer session data not purged
wp_commentsSpam comments not deleted
wp_actionscheduler_*WooCommerce scheduled actions accumulating

Best Practices

  1. Check DB size monthly to catch unexpected growth early.
  2. Use --tables to identify the specific source of bloat.
  3. Pair with wp db optimize after cleaning large tables.
  4. Delete plugin data from deactivated plugins — they often leave orphaned tables.
  5. Purge transients regularly with wp transient delete --expired.

Troubleshooting

ProblemCauseFix
Reported size is much smaller than actualInnoDB fragmentationRun wp db optimize to reclaim space
Unknown tables in outputOld plugin tables not cleaned upRemove manually with wp db query "DROP TABLE ..."
Access denied on information_schemaDB user lacks SELECT on information_schemaGrant access or use root credentials

Quick Reference

wp db size                             # Total DB size in bytes
wp db size --size_format=mb # Total in MB
wp db size --tables --size_format=mb # Per-table in MB
wp db size --tables --format=csv # CSV for spreadsheet

Next Steps