How to Clean Up Bloated Database Tables

Last modified: October 16, 2025

WordPress databases can grow large over time as data accumulates. This may cause slow queries, large backups, and lag in the admin dashboard. The most common issue is the wp_postmeta table, though plugins can also create oversized custom tables. Cleaning this data improves site performance but requires caution.

Before You Begin

Follow these steps before making any database changes:

Using Plugins for Quick Cleanup

For basic maintenance or simple cleanup, you can use a database optimization plugin. These tools remove unnecessary data such as old revisions, trashed posts, and expired transients with minimal setup or technical knowledge.

Two reliable options include:

These plugins are convenient for quick cleanup tasks. However, they are limited in scope and may not fully resolve deep database bloat. For large sites or WooCommerce stores, a manual cleanup following the steps below provides more targeted and lasting results.

Understanding Database Tables

WordPress stores all site data in database tables. Some key core tables include:

  • wp_posts: Posts, pages, and custom post types.
  • wp_postmeta: Key-value metadata for each post.
  • wp_options: Site-wide settings, transients, and plugin options.
  • wp_comments and wp_commentmeta: Comments and related metadata.

These tables can grow when plugins or themes add fields, logs, or temporary data that are never removed.

Example Use Case

A WooCommerce site that runs for years without cleanup might collect several million rows in wp_postmeta and hundreds of thousands more in plugin log tables. This can slow both the front and back end of the site.

How WooCommerce Uses wp_postmeta

WooCommerce stores product, order, and customer data in wp_postmeta. Each order creates multiple meta entries (for example, _billing_email, _shipping_method, _line_total). Extensions may add even more data.

This design is flexible but inefficient for large stores. Old orders and cached data can quickly expand the table.

High-Performance Order Storage (HPOS)

WooCommerce’s High-Performance Order Storage (HPOS) feature moves order data into dedicated tables (wc_orders, wc_order_addresses, etc.) for faster queries and a smaller wp_postmeta table.

Enable HPOS if supported by your WooCommerce version. Follow Using HPOS for setup instructions.

Identifying Problem Areas

Using Query Monitor

Use Query Monitor to find heavy or repetitive database queries. Watch for:

  • Frequent meta queries (meta_key or meta_value lookups)
  • Queries on large tables (wp_postmeta, plugin logs, etc.)
  • High query counts or missing indexes

See our full guide on Using Query Monitor.

Using WP-CLI or SQL

Check table sizes with WP-CLI:

wp db query "SELECT table_name, ROUND((data_length + index_length) / 1024 / 1024, 2) AS size_mb FROM information_schema.tables WHERE table_schema = DATABASE() ORDER BY size_mb DESC;"

This query lists all tables and shows their total size in megabytes, sorted from largest to smallest. It helps pinpoint where bloat occurs.

Reviewing Data in phpMyAdmin

  1. Log in to phpMyAdmin via the phpMyAdmin link in the Pressable control panel.
  2. Select your database.
  3. Open the Structure tab to view table sizes and row counts.
  4. Identify large or plugin-related tables. Sorting by the “Size” or “Rows” columns can help.
  5. Export tables before making changes using Export.

See our guide on Using phpMyAdmin for more details.

Reviewing Data via SSH / WP-CLI

To create a backup before cleanup:

wp db export /tmp/backup-before-cleanup.sql

This stores a secure copy of your database. You can restore from this backup, if needed, with:

wp db import /tmp/backup-before-cleanup.sql

Check table sizes:

wp db query "SHOW TABLE STATUS LIKE 'wp_%';"

This shows data length, index size, and row count for each table.

Why TRUNCATE Is Not the Right Solution

TRUNCATE TABLE deletes all rows instantly and resets counters. It is not safe for live databases because it removes all data without conditions and can break relationships. Use conditional deletions instead to control which rows are removed.

Using Conditional DELETE Safely

A safer approach is to use conditional queries to remove old or unnecessary data. Always confirm the rows you plan to delete with a SELECT statement first.

For example:

SELECT * FROM wp_postmeta WHERE meta_key LIKE '_transient_%';
DELETE FROM wp_postmeta WHERE meta_key LIKE '_transient_%';

You can also filter by date or ID range if applicable:

DELETE FROM wp_postmeta WHERE meta_id < 500000;

When deleting data that references other tables, check for orphaned entries. For example, removing posts may require cleaning up related postmeta rows:

DELETE FROM wp_postmeta WHERE post_id NOT IN (SELECT ID FROM wp_posts);

Always perform these operations on a staging site first.

Handling Plugin or Log Tables

Plugins often create their own tables for logs, analytics, or caching. Examples include:

  • wp_actionscheduler_logs
  • wp_rank_math_analytics_gsc
  • wp_yoast_indexable

Check whether the data is still being used. If it only contains old logs or reports, you can export it for archival use and then safely remove or truncate it on your staging site.

For example:

wp db export /tmp/plugin-logs-before-cleanup.sql
wp db query "TRUNCATE TABLE wp_actionscheduler_logs;"

If the plugin still needs historical data, consider setting retention limits or disabling excessive logging.

Preventing Future Bloat

  • Enable HPOS: Reduce reliance on wp_postmeta for WooCommerce orders.
  • Limit Logging: Adjust plugin settings to retain only recent logs.
  • Audit Plugins: Remove or replace poorly optimized plugins that generate unnecessary data.
  • Schedule Reviews: Review database size and slow queries on a regular basis.

Key Takeaways

Database bloat is common in long-running WordPress sites, particularly those running WooCommerce or heavy plugins. By safely inspecting, backing up, and cleaning unnecessary data, you can improve both performance and manageability.

Next Steps:

  • Review your database size monthly.
  • Use Query Monitor to track problematic queries.
  • Clean up safely using the techniques outlined above.

If you notice persistent slow performance after cleanup, review Using APM Insights to Troubleshoot Performance Issues for deeper analysis.