The Complete Guide to Database Optimization

A technician pulling a drive from a database server rack beside a laptop

Your WordPress database accumulates clutter over time. Post revisions, auto-drafts, spam comments, expired transients, and orphaned metadata build up with every edit, every spam attempt, and every plugin install. A bloated database is slower to query, and slower queries mean slower page generation — even with page caching enabled, because the cache must be regenerated eventually.

What Accumulates in Your Database

  • Post revisions. WordPress saves a copy of every post every time you click “Save Draft” or autosave triggers. A post you have edited 50 times has 50 revisions stored in the database. Most sites do not need more than the last 3-5 revisions.
  • Auto-drafts. WordPress creates an auto-draft every time you open the post editor, even if you never publish or save. These accumulate indefinitely.
  • Spam and trashed comments. Deleted comments are not removed from the database by default — they are moved to the trash, where they sit until manually emptied.
  • Expired transients. Transients are temporary cached values used by WordPress and plugins. Expired transients should be deleted automatically, but many are not — they linger in the options table, bloating it over time.
  • Orphaned post metadata. When a post is deleted, its metadata — custom fields, SEO data, view counts — is not always cleaned up. These orphaned rows serve no purpose and slow down queries on the postmeta table.

How to Clean Up Safely

The most important rule of database cleanup: never delete anything without seeing a summary first. Caching Out shows you exactly what will be cleaned — how many revisions, how many spam comments, how many expired transients — before anything is deleted. You review the summary, confirm, and then the cleanup runs. This is not optional; it is a safety requirement.

After cleanup, Caching Out can also optimize your database tables — the MySQL equivalent of defragmenting a hard drive. This reclaims space and improves query performance, particularly on large sites with millions of rows.

How Often Should You Clean Up?

For most sites, a monthly database cleanup is sufficient. High-traffic sites with frequent content updates — news sites, large WooCommerce stores, membership platforms — may benefit from weekly cleanup. Caching Out can schedule automatic cleanups on a daily, weekly, or monthly basis.

Further reading: How Page Caching Works — database optimization reduces the time it takes to regenerate cached pages, making your entire performance stack more efficient.

More from the blog

Ready when you are

One plugin, every optimisation, from $59 a year.

Install it, turn on what you need, and measure the difference on your own site. If it does not do what this site says, the 14-day guarantee means you get your money back.

  • No code required
  • Setup in under 3 minutes
  • 14-day money-back guarantee
  • 14-day money-back guarantee
  • Works on standard shared and managed hosting
  • Cancel anytime

Free edition · WordPress.org

Get Caching Out for free

Good call. Page caching is the biggest single speed win, and it is on the moment you activate. Two ways to install the free edition:

Option 2

Upload the zip

Download the plugin zip, then go to Plugins → Add New Plugin → Upload Plugin and choose the file.

Download free plugin (.zip)

After you activate, caching is already running. Open Caching Out → Setup Wizard to see what is on and why.

Want every feature from day one? Pro from $59/yr