Over time, your WordPress database can accumulate data that is no longer needed. Old revisions, expired transients, deleted content, and leftover metadata can increase database size and contribute to slower database queries.
Siteligent's Database Optimizer provides targeted cleanup and optimization tools that help keep your database maintained without requiring you to work directly with database tables.
Database Cleanup Options
Siteligent provides nine database optimization operations:
Expired Transients: Removes temporary WordPress options whose expiration time has passed. Transients are commonly used to temporarily store cached data. Once they have expired, they are no longer needed and can be removed.
Post Revisions: Removes older revisions of posts and pages while preserving the current content. WordPress can accumulate many revisions over time, particularly on sites where content is edited frequently.
Auto-Drafts: Removes automatically saved draft entries that are no longer needed.
These can accumulate when posts or pages are started but never published.
Trashed Posts: Permanently removes posts that are already in the WordPress trash.
Spam Comments: Removes comments that have been marked as spam.
Trashed Comments: Permanently removes comments that have already been moved to the trash.
Orphaned Post Meta: Removes post metadata that belongs to posts that no longer exist. This helps clean up database records left behind after content has been deleted.
Orphaned Comment Meta: Removes comment metadata associated with comments that have already been deleted.
Optimize Tables: Optimizes database tables to reclaim unused space and improve the organization of table data where applicable.
How Siteligent Handles Large Databases
Database cleanup can become resource-intensive on larger WordPress sites. Running a large cleanup operation in one request can consume significant memory or hit PHP execution limits.
Siteligent therefore processes database cleanup in controlled batches.
Batch Processing
Cleanup operations process up to 500 records per run. Siteligent keeps track of the remaining records and returns the number of records processed. If more records remain, subsequent runs can continue the cleanup rather than attempting to process the entire database in a single request.
Index-Friendly Cleanup Queries
For orphaned metadata cleanup, Siteligent uses index-friendly LEFT JOIN queries rather than NOT IN subqueries.
This approach helps avoid unnecessarily expensive full-table operations and reduces the risk of database locks during cleanup.
Table Optimization Limits
Table optimization is also deliberately limited to prevent long-running database operations.
Siteligent processes a maximum of 10 tables per run and stops automatically when execution approaches its safety threshold. The optimization process is designed to stop around 18 seconds, with a maximum execution target of 20 seconds, helping reduce the risk of PHP timeout errors.
Back Up Before Optimizing a Production Site
Although these operations are designed to be safe and are processed in controlled batches, database changes should still be treated carefully on live production websites.
Before running database optimization on an important production site, create a manual database backup first.
This gives you a recovery point if you need to restore the database after an unexpected issue.
When Should You Run Database Cleanup?
Database cleanup can be useful when:
Your site has accumulated a large number of post revisions.
Expired transients have accumulated.
Large amounts of content have been deleted.
Your database contains orphaned metadata.
You want to reclaim unused database space.
You're investigating database-related performance issues.
For routine maintenance, focus on the cleanup operations that actually have accumulated data rather than repeatedly running every available operation.
A Safe Maintenance Approach
For a production website, a sensible workflow is:
Create a database backup.
Review the available database cleanup options.
Run the required cleanup operation.
Allow the operation to complete its batches.
Check the website and important functionality afterward.
Run additional cleanup operations only when needed.
This keeps database maintenance controlled while giving you a recovery point before making changes.
