Posted on

Cleaning up your WooCommerce Database

Glasses sitting in front of computer screens displaying code

There’s lots you can do to improve database (DB) performance, but each change comes with risks. Always thoroughly test changes in a development environment first before making permanent database changes in production.

Growth in data requires a growth in hosting to handle the scale of database size and queries.

There’s only so much you can clean-up practically. When you reach this point, hosting with solid managed hosting like or custom cloud infrastructure like AWS can offer a great deal of scale, costing on the magnitude of $5k/mo in huge DB servers if it becomes too important to have all the historic data while keeping things fast. Those costs are out of reach for most of us, so minding your DB health is critical as you grow so you don’t have to spend huge on hosting before it’s truly necessary to do so.

There may even come a point where it makes sense to shard the data (i.e. move historic quarters or years data over to backup environments for archival usage).

The best solution will depend on each client’s unique needs.

Here’s my practical tips in this area:

1) Ensure the DB uses InnoDB tables.

To generate update queries:

2) Use WP Optimize plugin.

This can clear out orphaned records, old drafts, etc.

3) Use my Prune Orders plugin.

This can trash all old failed, pending, cancelled orders by selected status to a specified date.

4) Delete legacy post types, post meta, and user meta data.

For example: old order metadata, Google analytics meta, address fields, etc. To see the offenders in order of size:

5) Examine wp_options table health.

Remove old plugin cruft. To see how many MB are loading with each page request from wp_options run this to see which rows are hogging up the most space and decide which can be removed:

6) Run through New Relic APM.

Install the site onto a free dev environment, run some front and back end tests and examine the reports to find any problem PHP or SQL executions.

7) Move products to their own tables.

CAUTION: may break any plugin or code snippet that doesn’t use C.R.U.D. functions from v3.0. Check out the Custom Product Tables BETA project.

8) Move orders to their own tables

CAUTION: may break any plugin or code snippet that doesn’t use C.R.U.D. functions from v3.0. Check out the Custom Order Tables BETA project.