A client’s WordPress site has gotten progressively slower over three years. The database is 2GB, the wp_options table has 15,000 rows (many from uninstalled plugins), and post revisions are eating storage.
What is a safe database cleanup checklist that will not break anything?
Safe cleanup checklist:
- Backup the database first. Always.
- Delete post revisions:
DELETE FROM wp_posts WHERE post_type = 'revision'
- Delete auto-drafts:
DELETE FROM wp_posts WHERE post_status = 'auto-draft'
- Delete trashed posts:
DELETE FROM wp_posts WHERE post_status = 'trash'
- Delete orphaned postmeta:
DELETE pm FROM wp_postmeta pm LEFT JOIN wp_posts p ON p.ID = pm.post_id WHERE p.ID IS NULL
- Delete transient options:
DELETE FROM wp_options WHERE option_name LIKE '_transient_%'
- Optimize tables:
wp db optimize via WP-CLI
- Add
define('WP_POST_REVISIONS', 5) to wp-config to limit future revisions
The autoloaded options in wp_options are usually the biggest performance issue. Check for plugins that set autoload=yes on large serialized arrays. Remove autoload from options that do not need to be loaded on every page.
also check if you have a persistent object cache (Redis or Memcached). For a 2GB database, an object cache makes a dramatic difference because WordPress queries wp_options on literally every page load. With Redis, that query hits memory instead of disk.
Perfect, exactly what I needed. Going to run through this checklist on staging first. The autoloaded options issue is probably the culprit - I bet half those 15K rows are autoloaded remnants from old plugins. @serverside_jay Redis is already on the server but not configured for WordPress, going to set that up too.
In the DACH region this is standard practice. The German market has different expectations for CMS governance than the US market.
Crawl the staging site before go-live and diff against the production crawl. Every discrepancy in page count, status codes, or canonical URLs is a bug.
The CMS market consolidates every decade. We are overdue for the next consolidation.
I inherited this exact setup on a client site last year. The previous developer left no documentation. Took two weeks just to understand what all the plugins were doing.