Think of your database as the brain of your website. It remembers everything. Every draft you ever saved, every spam comment you deleted, and the settings for that one plugin you uninstalled three years ago. All of that extra weight slows things down.
By cleaning out the clutter, you reduce the workload on your server every time a visitor clicks a link. Here are seven steps to get it done safely.
1. Put a Cap on Post Revisions
WordPress saves a brand-new revision every single time you hit “Save Draft.” If a post takes you a few days to write, you might have 50 hidden copies of it just sitting in your database.
You can stop this hoarding by adding one single line to your wp-config.php file:
define( ‘WP_POST_REVISIONS’, 5 );
This forces WordPress to only remember the last five versions of any post. (Pro tip: Always back up your site before touching core files).
2. Take Out the Trash
This is the easiest win on the list. Spam comments and trashed posts don’t delete themselves immediately. They just sit there taking up space.
Head into your dashboard, click on Comments, filter by Spam, and wipe them out permanently. Do the same for your Trash folder. If you run a high-traffic site, doing this regularly keeps things surprisingly lean.
3. Clear Out Stuck Transients
Transients are temporary bits of data that your site caches to load things faster (like social share counts). They are supposed to delete themselves when they expire. Sadly, they often get stuck.
You can easily clear them out using a free database optimization plugin, or by running a quick WP-CLI command if you’re comfortable in the terminal:
wp transient delete –expired
4. Check Your Autoloaded Options (The Big One)
This step trips up a lot of people, but it’s crucial. Autoloaded options are settings that load on every single page view. If this gets too bloated, your server has to work overtime before the page even starts loading.
WordPress recommends keeping your autoloaded data under 800 KB.
Don’t go randomly turning things off, though. Find out which specific plugin is hogging the space. If a plugin you rarely use is loading massive amounts of data globally, it might be time to find a lightweight alternative.
5. Delete “Ghost” Data from Old Plugins
Ever install a plugin, hate it, and delete it? Yeah, it probably left its settings behind in your database.
Before deleting a plugin, look for an “uninstall completely” option in its settings. If you’re using a database manager later to manually delete old tables, be incredibly careful. Never delete a table just because the name looks weird. If you don’t know what it does, leave it alone.
6. Optimize the Tables
Once you’ve deleted the junk, your database tables will have empty gaps in them. You need to pack everything back together—sort of like defragmenting an old hard drive.
You can use a quick terminal command (wp db optimize) or simply click the “Optimize Database” button in caching plugins like LiteSpeed or WP-Sweep.
7. Use Object Caching
Want to stop your site from constantly bombarding the database with the exact same requests? Set up persistent object caching (like Redis or Memcached).
It remembers frequent database queries so WordPress doesn’t have to keep asking for the same information twice. Most quality web hosts offer this out of the box now, and turning it on is a massive performance boost.
A Realistic Maintenance Routine
You definitely don’t need to do this every day. Here is a simple, low-stress schedule to keep things running fast:
- Weekly: Empty your spam and trash.
- Monthly: Check your overall database size and keep an eye on those autoloaded options.
- A few times a year: Do a deep clean of old plugin data and optimize your tables.
- The Golden Rule: Always run a full backup before doing a deep database clean.
A fast site isn’t just about throwing more server power at the problem. Keep your database lean, don’t go crazy installing dozens of plugins, and your site will run noticeably faster.