wp-cleanup-scripts is a collection of battle-tested WP-CLI bash routines and indexed SQL queries for cleaning bloated WordPress production databases. It safely purges expired transients, orphaned postmeta, post revisions, and Action Scheduler logs without locking high-traffic tables.
-- 1. Inspect top autoloaded wp_options bloat in bytes
SELECT option_name, LENGTH(option_value) AS bytes
FROM wp_options WHERE autoload IN ('yes', 'on')
ORDER BY bytes DESC LIMIT 20;
-- 2. Safely remove orphaned wp_postmeta rows with no parent post
DELETE pm FROM wp_postmeta pm
LEFT JOIN wp_posts p ON p.ID = pm.post_id
WHERE p.ID IS NULL;