Site icon Hostreta

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:

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:

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.

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:

Further reading: official WordPress documentation

Key Takeaways: WordPress Database

Exit mobile version