Your WordPress database is the engine behind every page load. It stores posts, pages, comments, user data, plugin settings, transients, and much more. Over time, databases accumulate bloat — post revisions, spam comments, orphaned metadata, expired transients, and fragmented tables — all of which slow down queries and degrade your site's performance. This guide covers how to clean, optimize, and maintain your WordPress database on SakuraHost.
Understanding Your WordPress Database
A standard WordPress installation creates 12 core tables (with the default wp_ prefix):
wp_posts— all content (posts, pages, revisions, attachments, custom post types)wp_postmeta— metadata for posts (custom fields, plugin data)wp_options— site settings, plugin options, transientswp_comments/wp_commentmeta— comments and their metadatawp_users/wp_usermeta— user accounts and profileswp_terms/wp_termmeta/wp_term_taxonomy/wp_term_relationships— categories, tags, and taxonomieswp_links— blogroll links (legacy, rarely used)
Plugins often add their own tables. A site with 20+ plugins may have 50-100 database tables. Learn more at the WordPress Developer Reference.
Common Sources of Database Bloat
Post Revisions
WordPress saves a revision every time you click Save Draft or Update. A post edited 50 times has 50 revisions stored in wp_posts, each with corresponding rows in wp_postmeta. On a busy blog, this can add thousands of unnecessary rows.
Transients
Transients are temporary cached data stored in wp_options by plugins and themes. Expired transients should be cleaned up automatically, but many plugins leave orphaned transients behind. A bloated wp_options table is one of the most common causes of slow WordPress queries because WordPress loads autoloaded options on every page request.
Spam and Trashed Comments
Spam comments and items in the trash consume database space. WordPress does not automatically purge the trash until 30 days have passed.
Orphaned Metadata
When you delete a post or comment, the corresponding metadata in wp_postmeta or wp_commentmeta sometimes remains as orphaned rows with no parent.
Plugin Leftovers
Many plugins do not clean up after themselves when deactivated or deleted. Custom tables, options, and transients may remain in your database indefinitely.
Method 1: WP-Optimize Plugin
WP-Optimize is a comprehensive database optimization plugin that handles cleaning, table optimization, and scheduled maintenance.
- Install from Plugins > Add New and activate
- Go to WP-Optimize > Database
- Review each optimization option:
- Clean all post revisions
- Clean all auto-draft posts
- Clean all trashed posts
- Remove spam and trashed comments
- Remove expired transients
- Clean orphaned post/comment metadata
- Optimize database tables
- Click Run all selected optimizations
In WP-Optimize > Settings, enable scheduled cleanups. We recommend weekly database optimization and monthly table optimization. This prevents bloat from accumulating.
Method 2: Advanced Database Cleanup via phpMyAdmin
For more control, you can optimize your database directly through phpMyAdmin in your SakuraHost cPanel.
In phpMyAdmin, select your WordPress database, click Check all at the bottom, choose Optimize table from the dropdown, and execute. This defragments tables and reclaims wasted space. Equivalent SQL:
Method 3: WP-CLI Database Optimization
If you have SSH access to your SakuraHost account, WP-CLI provides powerful database management:
Controlling Post Revisions
Prevent future bloat by limiting revisions. Add to wp-config.php:
Optimizing the wp_options Table
The wp_options table is unique because WordPress loads all rows with autoload='yes' on every single page request. A bloated autoload set is a common hidden performance killer.
Run this query in phpMyAdmin to see total autoloaded data size:
If this exceeds 1MB, you have optimization opportunities. Identify the largest autoloaded entries:
Large entries from deactivated or deleted plugins can safely have their autoload set to 'no' or be deleted entirely.
Database Optimization Schedule
We recommend this maintenance schedule for WordPress sites on SakuraHost:
- Weekly: Clean transients, spam comments, and trashed items (automate with WP-Optimize)
- Monthly: Optimize database tables and review autoloaded options size
- Quarterly: Audit installed plugins for orphaned tables, clean post revisions beyond the limit
- Before major updates: Full database backup and optimization
Monitoring Database Performance
Install Query Monitor to see exactly which database queries are running on each page, how long they take, and which plugin or theme triggers them. This is invaluable for identifying slow queries that need optimization or plugins that are making excessive database calls.
For more on WordPress database structure and optimization, see the WordPress Developer Reference and the MySQL OPTIMIZE TABLE documentation.