Smaller & leaner WordPress database dumps

I use WordPress database dumps a lot when running automated WordPress plugin tests using wp-browser, Codeception and ChromeDriver. This lets me start tests with a specific configuration every time.

Unfortunately WordPress stores a lot of redundant data in form of transients which makes database dumps larger than they should be. This transient data includes stuff like latest blog posts from wordpress.org.

Fortunately, it’s easy to get rid of this excess data. If it’s missing, WordPress will just regenerate it when it’s needed the next time. Here’s how you can do it.

  1. Create your minimal WordPress installation. Install the lowest WordPress version your plugin supports. You can also use WP CLI to downgrade to a specific version: wp core upgrade --version=5.0 --force
  2. It may be a good idea to reset the database to get rid of any redundant data. Easiest way to do this is to simply delete all the tables in the database. When you visit the site again using your browser, WordPress will take you through the famous 5-minute installation.
  3. Set up all the stuff you need for your tests. Install plugins, configure settings and create content.
  4. Delete transients. First, it’s a good idea to close all the browser windows that have to site open to make sure you don’t accidentally re-generate the transients. Easiest way to delete the transients is to use WP CLI. Delete all site transients by running wp transient delete --all .
  5. Delete network transients. For some reason, certain transients are “network” transients, even when when running a single site. These transients are prefixed by _site_transient_, rather than _transient_ in the wp_options table. You can delete them with the WP CLI command wp transient delete --network --all .
  6. Export the database dump using your favorite program (I like TablePlus)

Congratulations, you now have a clean database dump! Using these steps I reduced the size of my database dump from 645 KB to 42.4 KB. That’s a 93% decrease!