How to Clean Up a WordPress Database Before Migrating

WordPress never deletes anything on its own. Every autosave, every spam comment, every plugin's temporary cache entry sits in your database indefinitely — and by migration day, a lot of what you're exporting is dead weight that has nothing to do with your actual content.
Table of Contents
Why This Matters More at Migration Time
A bloated database is a performance annoyance day-to-day, but it becomes an active liability during a migration: bigger SQL dumps take longer to export and import, more rows mean more chances for an import to time out or hit a memory limit, and you don't want to spend hours mapping junk data into your new CMS's content model. Clean before you export, not after.
1. Post Revisions
WordPress autosaves a revision roughly every 60 seconds while a post is being edited. A post that's been edited on and off for a year can easily carry 50+ revision rows, none of which you need in the new system — you only want the published version.
2. Spam and Trashed Comments
Deleted comments go to trash, and spam comments sit in the spam queue — neither is purged automatically. A site getting even a modest trickle of spam can accumulate well over 100,000 spam comment rows in a year. None of it should make the trip to your new site.
3. Expired Transients
Transients are temporary cached values plugins store with an expiration timestamp, but WordPress doesn't proactively clean up ones that have already expired. A site running 15-20 plugins can build up thousands of stale transient rows in wp_options — a table that's loaded on every single page request, migrated or not.
4. Orphaned Post Meta
When a post is deleted, its wp_postmeta rows don't always go with it. Plugins that store custom field data are especially prone to leaving orphaned meta behind — rows referencing a post ID that no longer exists anywhere in wp_posts.
5. Auto-Drafts and Unused Media
- Auto-drafts: WordPress creates one every time you open the "Add New Post" screen, even if you never save it.
- Orphaned media: images uploaded and never inserted into any post, still taking up space in your media library export.
How to Do It Safely
- Take a full database backup first — this is not optional. Cleanup deletes rows permanently.
- Use a dedicated cleanup plugin (WP-Sweep, Advanced Database Cleaner) rather than hand-writing DELETE queries against production data.
- Cap revisions per post (via a filter or a plugin setting) rather than deleting all history if you might still need recent edits.
- Re-run the export size check after cleanup — you should see a meaningfully smaller SQL dump.
Then Export for Real
Once the database is clean, follow our full export guide to pull posts, media, users, and SEO metadata in the right order, and check the complete WordPress migration checklist for everything else that needs to happen before and after the move. If database bloat has been dragging down your current site's performance independent of any migration, our breakdown of the real ongoing cost of running WordPress covers why that keeps happening.




Comments