HowTo

How to Clean Up a Slow WordPress Database

WordPress Database – How to Clean Up a Slow WordPress Database

In this guide: How to clean up a slow WordPress database: why databases get bloated, backing up first, removing revisions and spam, optimizing tables, and automating cleanup.

Every WordPress site stores its content, settings, and activity in a database. Over time, that database collects clutter: hundreds of post revisions, spam comments, expired temporary data, and leftover tables from plugins you deleted years ago. A bloated database can slow down your admin area and dynamic pages.

Here’s how to clean it safely.

Why databases get bloated

Common sources of database clutter:

  • Post revisions: WordPress saves a revision every time you save a draft or update a post. A frequently edited post can have dozens.
  • Auto-drafts and trashed posts.
  • Spam and trashed comments.
  • Expired transients: temporary cached data stored by plugins that sometimes isn’t cleaned up.
  • Orphaned metadata: post meta, comment meta, or user meta left behind after content was deleted.
  • Leftover plugin tables and options: many plugins don’t remove their data when uninstalled.
  • Autoloaded options: data in the wp_options table loaded on every page request. Too much autoloaded data slows every page.
  • Logs: security, email, and activity log plugins can create very large tables.
  • WooCommerce sessions and action scheduler logs.

Backing up first

Always back up your database before cleaning. Deleting data is permanent.

  1. Use your backup plugin or hosting backup tool to create a fresh backup.
  2. Download a copy or ensure it’s stored off-site.
  3. For large or critical sites, test the cleanup on a staging copy first.

See Website Backups: The 3-2-1 Rule Explained.

Cleaning revisions and spam

The easiest method is a cleanup plugin such as WP-Optimize, Advanced Database Cleaner, or the database tools in LiteSpeed Cache or WP Rocket.

Typical cleanup tasks:

  • ☐ Delete post revisions (optionally keep the last few).
  • ☐ Delete auto-drafts.
  • ☐ Empty trashed posts and comments.
  • ☐ Delete spam comments.
  • ☐ Delete expired transients.
  • ☐ Remove orphaned post and comment meta.

Limit future revisions by adding this line to wp-config.php:

define( 'WP_POST_REVISIONS', 5 );

This keeps the five most recent revisions per post — enough for safety, without endless buildup.

Leftover plugin tables: tools like Advanced Database Cleaner can identify tables and options not used by active plugins. Be careful — only delete data you’re sure belongs to removed plugins.

Large log tables: configure logging plugins to keep only 30–90 days of data, or disable logs you don’t use.

Optimizing tables

After deleting data, database tables may still hold unused space. Optimizing reorganizes tables and reclaims that space.

  • Most cleanup plugins include an “optimize tables” option.
  • You can also use phpMyAdmin: select tables → “Optimize table.”

Check autoloaded data:
The wp_options table can slow your site if it contains too much autoloaded data. Some cleanup plugins and Site Health tools show autoloaded data size. Large autoloaded entries from deleted plugins can often be removed or set to not autoload — carefully.

Use object caching: for busy sites, Redis or Memcached reduces repeated database queries — ask your host.

Check the database engine: modern WordPress tables should use InnoDB, not the old MyISAM engine. Your host can help convert.

Automating cleanup

Set it and forget it:

  1. Schedule a weekly cleanup of revisions, spam, trash, and transients in your cleanup plugin.
  2. Keep WP_POST_REVISIONS limited.
  3. Set log retention limits in security and email log plugins.
  4. Empty trash automatically (WordPress does this after 30 days by default; you can change it with EMPTY_TRASH_DAYS).
  5. Review database size monthly as part of your maintenance routine — see Monthly Website Maintenance Checklist.

What not to do:

  • Don’t delete tables you don’t recognize without research.
  • Don’t run aggressive cleanup on a live WooCommerce store during peak hours.
  • Don’t skip backups.

Further reading: official WordPress documentation

Key Takeaways: WordPress Database

  • Revisions, spam, transients, logs, and leftover plugin data bloat databases.
  • Always back up before cleaning.
  • Use a cleanup plugin to remove clutter and optimize tables.
  • Limit revisions, control logs, and schedule weekly automatic cleanup.
Z
zasma171

Writes for Hostreta about the topics covered in this article.

Comments (0)

Your email address will not be published. Required fields are marked *

Recent Comments

No comments to show.
Ad · AdSense
Ad space 300×250
Affiliate links
Tools we recommend
Protect Your Website with Automated Daily Backups
$2.09
Get it
the easiest way to manage all of your social media accounts
$29
Get it
Starter Website Get online, properly
$249
Get it
google workspace Business Starter
$3.75
Get it
Nord Vpn Cybersecurity. Built for Everyday Use
$8.99
Get it

We may earn a commission on purchases made through these links, at no extra cost to you.

Ad · AdSense
Ad space 300×600
Ad · AdSense
Ad space 300×600

$ top hosting picks

affiliate
★★★★★

NovaHost

$2.95/mo,renews at $9.95
  • Free SSL + domain, first year
  • 1-click WordPress install
  • 24/7 chat, sub-5-min response
get this deal →
affiliate link · we may earn a commission
★★★★★

CloudRoot

$4.50/mo,renews at $12.95
  • Built-in CDN + caching
  • Daily backups, 30-day retention
  • Staging environments included
get this deal →
affiliate link · we may earn a commission
★★★★★

ByteForge

$3.75/mo,renews at $10.95
  • NVMe storage on every plan
  • Unlimited bandwidth
  • Free migration from your old host
get this deal →
affiliate link · we may earn a commission

Never miss a new article

Join thousands of developers and builders getting a weekly digest of the best tech articles.