How to improve WooCommerce site speed by cleaning up your WordPress database

Slow WooCommerce sites are often blamed on hosting or heavy plugins—but in many cases, the real issue is database bloat. In this case, performance issues were traced to inefficient database queries caused by excessive stored data, including expired transients, old orders, and background task logs.

By performing a targeted database cleanup and optimization, load times were significantly reduced, backend responsiveness improved, and overall site performance increased—without requiring any infrastructure changes.

Issue Background

A WooCommerce-powered WordPress site was experiencing inconsistent performance:

  • Fast frontend performance on static pages
  • Slower load times on WooCommerce and database-driven pages
  • High query load affecting backend responsiveness
  • Poor “real feel” speed despite decent caching

Initial analysis revealed:

  • A heavily bloated database (~1GB in size)
  • Large amounts of expired and unnecessary data
  • Inefficient queries tied to WooCommerce order and subscription data
  • Accumulated background processes via Action Scheduler

The goal was to improve performance using database optimization alone, before considering more complex solutions like infrastructure upgrades or WooCommerce HPOS migration.

Diagnosis

The investigation focused on identifying database inefficiencies impacting WooCommerce queries.

Key findings:

  • Excessive Action Scheduler entries
    Over 120,000 non-pending actions stored unnecessarily
  • Expired transients and sessions
    Hundreds of expired transients still stored in the database; WooCommerce session data not being cleared properly
  • Old WooCommerce order and subscription data
    Large volume of pre-2023 orders and cancelled subscriptions; some parent orders required for subscription integrity
  • Database table bloat
    Oversized wp_posts, wp_postmeta, and WooCommerce tables with heavy fragmentation
  • Orphaned data
    Unused postmeta, order_items, and order_itemmeta entries
  • Frontend media inefficiencies
    Large unoptimized video assets impacting load time

Resolution Steps

1. Back up the database

Before making any changes, a full database backup was created to ensure safe rollback if needed.

2. Clean up old WooCommerce data

  • Removed 558 cancelled subscriptions (shop_subscription, wc-cancelled, before Jan 1, 2023)
  • Preserved all active and relevant subscriptions (wc-active, wc-on-hold, wc-pending-cancel)
  • Retained necessary parent orders to maintain subscription relationships
  • Exported legacy order data to CSV for archival purposes

3. Remove Action Scheduler bloat

  • Deleted 123,770 non-pending actions
  • Preserved all scheduled and future tasks

4. Delete expired transients and sessions

  • Removed 690 expired transients
  • Cleared all expired WooCommerce sessions

5. Clean orphaned database entries

  • Removed orphaned postmeta
  • Removed unused order_items
  • Removed unlinked order_itemmeta

6. Optimize database tables

Performed optimization across key tables including posts, postmeta, WooCommerce order tables, options, Action Scheduler tables, sessions, comments, and metadata.

7. Reduce database size and fragmentation

  • Database size reduced from ~1024 MB to ~761 MB
  • Fragmented/free space reduced from ~481 MB to ~141 MB

8. Clear caching layers

Flushed all caching layers to ensure changes were reflected sitewide.

9. Optimize frontend assets

  • Converted large homepage video from 4K MP4 to optimized Full HD WebM format

Final Outcome

After completing the database cleanup and optimization:

  • Query execution time was significantly reduced
  • Backend responsiveness improved
  • WooCommerce pages loaded faster and more consistently
  • Overall site performance and “real feel” speed improved

Performance testing showed measurable improvements, including a jump from a C grade to an A grade in GTmetrix and nearly 50% faster load times in Query Monitor.

While these optimizations delivered major gains, further improvements may require migrating WooCommerce to High-Performance Order Storage (HPOS) or implementing additional infrastructure enhancements.

If your WooCommerce site is slowing down and you’re not sure why, Freshy can help diagnose and optimize your setup.
Contact Freshy