WordPress database optimization is the process of cleaning and reorganizing the MySQL or MariaDB database that powers your WordPress site — and for South African businesses already tracking the full cost of running a website, skipping this step is one of the quieter ways to leave server performance on the table. Every page request your site serves — from the home page to a product listing — runs database queries first. The more bloat those queries wade through, the slower your server response time.
A new WordPress installation ships with 12 default database tables. Within a year of normal use — publishing content, installing and removing plugins, processing WooCommerce orders — those tables accumulate unnecessary rows: unlimited post revisions, expired transient data that plugins leave behind, spam comments, and orphaned metadata from plugins removed without cleaning up after themselves. On shared hosting plans common in South Africa, where database connections and memory are shared across multiple sites on the same server, that accumulation compounds the performance hit.
The five cleanup tasks in this guide are ordered by effort-to-impact ratio. The two highest-leverage steps do not require SSH access or a developer, and all five can be completed free of charge using a single plugin. If you are also thinking about what a maintained WordPress site costs month to month, the breakdown of what a website costs to run per year covers hosting, maintenance, and platform fees in full.
Quick Answer
WordPress database optimization removes accumulated bloat — expired transients, unlimited post revisions, spam comments, and orphaned plugin data — from the MySQL or MariaDB database your WordPress site runs on. Cleaning these tables reduces the autoloaded data WordPress fetches on every page request (target: under 800 KB), lowers server response time, and shrinks backup file sizes. The free WP-Optimize plugin handles all five priority tasks on demand; automatic scheduling requires the premium version, but a monthly manual run takes under five minutes.
Is your WordPress site running slower than it should?
Tell us your URL and current hosting setup and we will identify whether database bloat, a caching gap, or something else is the bottleneck — before any work is quoted.
Get a No-Obligation Site ReviewWhat WordPress database optimization actually does
WordPress database optimization cleans, compacts, and restructures the tables your site reads from on every page load, so database queries execute with less overhead and return results faster. The official WordPress Advanced Administration Handbook identifies two primary database-level levers: keeping autoloaded options under 800 KB, and minimizing stored post revisions.
The autoload mechanism is the most directly performance-relevant lever. On each page request, WordPress runs one query that pulls all autoloaded option rows from the wp_options table into memory simultaneously. Those rows include plugin settings, theme configuration, and transient data that plugins flag as "autoload=yes" when they write to the database.
A healthy site keeps this query's payload under 800 KB — when it grows to several megabytes on a neglected site, every page load slows by a proportional amount because that query must complete before WordPress renders anything.
The OPTIMIZE TABLE operation — available through phpMyAdmin or via WP-CLI — reorganizes fragmented table storage. After rows are deleted in bulk (as during a revision cleanup), the storage space those rows occupied is marked as free but not reclaimed. OPTIMIZE TABLE rebuilds the table file and compacts that fragmented space. On modern WordPress installations using InnoDB tables, it also rebuilds the indexes. On InnoDB tables, MySQL returns the message "Table does not support optimize, doing recreate + analyze instead" — this is expected and can be safely ignored; the table is rebuilt successfully.
What causes database bloat on SA WordPress sites
Database bloat accumulates from five recurring sources, and WooCommerce-enabled sites — widely used across South African retail, service businesses, and ecommerce — accumulate it faster because order metadata adds rows to wp_postmeta at every transaction.
- Post revisions: By default, WordPress stores an unlimited number of revisions for every post and page. A site with 500 posts averaging 20 revisions each carries 10,000 revision rows on top of its 500 live content rows — and those revision rows sit in the same wp_posts table as live content.
- Expired transients: Transients are temporary cache entries that plugins write to wp_options with an expiry timestamp. When a transient expires, WordPress should delete it the next time the code calls
get_transient()— but if the plugin that wrote it is deactivated or the transient key is never called again, those rows remain indefinitely. Sites with 30 or more active plugins can accumulate tens of thousands of expired transient rows. - Spam and trashed comments: WordPress retains spam-marked and trashed comments in wp_comments until they are permanently deleted. A site receiving comment spam without automatic deletion turned on can carry hundreds of thousands of rows doing nothing except inflating table scans.
- Orphaned post metadata: When a post is deleted, WordPress does not automatically remove the associated rows in wp_postmeta. Plugins that store per-post data face the same issue: removing a plugin without running its uninstall routine leaves orphaned rows attached to posts that no longer exist.
- Deactivated plugin settings: Deactivating (rather than uninstalling) a plugin typically leaves its settings in wp_options with autoload=yes. Those settings are pulled into memory on every page request even after the plugin is gone from the site.
For businesses on shared hosting — where database connection limits and memory ceilings are pooled infrastructure — the cumulative effect of all five sources is measurably slower server response times, a sluggish admin dashboard, and larger backup files that take longer to create and store.
Five Cleanup Steps Ordered by Page-Load Impact
The tasks below are ordered by effort-to-impact ratio: the two highest-leverage tasks deliver the largest improvement to page load time and require no command-line access. Run them in this sequence on a first-pass cleanup — and always take a full database backup before starting.
| # | Task | Primary Table | Impact | Effort | Frequency |
|---|---|---|---|---|---|
| 1 | Clear expired transients | wp_options | High — reduces autoload payload | Low — one click in WP-Optimize | Monthly |
| 2 | Delete existing post revisions | wp_posts, wp_postmeta | High — shrinks largest content tables | Low — one click in WP-Optimize | Once, then cap |
| 3 | Remove spam and trashed comments | wp_comments, wp_commentmeta | Medium — depends on comment volume | Low — one click in WP-Optimize | Monthly |
| 4 | Clean orphaned post metadata | wp_postmeta | Medium — especially on WooCommerce sites | Medium — requires plugin or WP-CLI | Quarterly |
| 5 | Run OPTIMIZE TABLE | All tables | Medium — reclaims fragmented storage | Low — plugin or phpMyAdmin | Quarterly |
Before any cleanup, take a full backup. WP-Optimize includes a backup step before cleanup runs; your hosting control panel's backup tool also works. OPTIMIZE TABLE briefly locks the table it is rebuilding — schedule it during a low-traffic window. If your hosting plan is on infrastructure exposed to load-shedding, avoid overlapping with scheduled outage windows to prevent an interrupted optimization mid-run.
With these five tasks complete, your WordPress database optimization delivers its maximum benefit before any caching layer is applied. Clean tables behind a well-configured caching plugin load faster than uncleaned tables behind the best caching plugin available.
How to prevent database bloat from returning
Running the cleanup once without changing the settings that produce bloat means repeating the same work in three to six months. Two changes stop the two largest sources before they accumulate again.
Cap post revisions in wp-config.php
Add one line to your wp-config.php file, placed before the require_once call at the bottom of the file:
define( 'WP_POST_REVISIONS', 5 );
This caps every post and page at five stored revisions. Most practitioners recommend between 3 and 5 — enough to recover from an accidental overwrite, not enough to rebuild significant bloat within weeks. Setting the constant to 0 disables revisions entirely; keeping a small number is generally better for a business site with multiple contributors. The constant is safe across WordPress core updates: WordPress never overwrites wp-config.php during an upgrade.
Uninstall plugins — do not just deactivate them
When you deactivate a plugin, its option rows remain in wp_options, often flagged for autoloading. Uninstalling a plugin through the WordPress admin (Plugins → Delete) triggers that plugin's cleanup routine, removing its database rows. Not every plugin does this cleanly — the Advanced Database Cleaner plugin can identify and remove orphaned option rows left behind by incomplete uninstalls.
WordPress 6.6 and later autoload improvements
Some managed hosts and newer WordPress versions include mechanisms to limit autoloading of large option values — check your host's documentation for details. Even so, a full WordPress database cleanup of existing expired transients and revision rows is still worthwhile: any such mechanism prevents large new option values from being autoloaded, but does not remove rows that already exist in the database.
Not sure which tasks apply to your hosting setup?
Share your hosting plan and WordPress version and we will map the right sequence — shared hosting, managed WordPress, and VPS each have a different starting point and different tools available.
Ask Us DirectlyFour tools to maintain your WordPress database
The right tool for database maintenance depends on your hosting plan and technical comfort level. Four tools cover the full range from one-click non-technical cleanup to developer-grade SQL access.
| Tool | Access Required | Cost | Best For |
|---|---|---|---|
| WP-Optimize | WordPress admin | Free (premium adds multi-site and automatic scheduling; free version runs all tasks on demand) | Non-technical operators — covers all five cleanup tasks on demand (automatic scheduling requires premium) |
| Query Monitor | WordPress admin | Free | Identifying slow queries (>0.05s) and which plugins generate the most database load |
| WP-CLI | SSH / command line | Free | VPS or managed hosting users who want scriptable, repeatable operations (e.g., wp db optimize, wp transient delete --expired) |
| phpMyAdmin | cPanel / hosting panel | Free via host | One-off manual table inspection, converting MyISAM tables to InnoDB, or running the OPTIMIZE TABLE command on specific tables |
WP-Optimize is the most practical plugin for this type of WordPress database cleanup on standard SA shared hosting — it needs no SSH access, the free version covers every task in the priority table above on demand — set a monthly calendar reminder to run it, or upgrade to premium for automatic scheduling. For hosts that allow SSH access, WP-CLI is the more efficient route: use wp db optimize to optimize your WordPress database tables in one command, and wp transient delete --expired to remove only expired transients without touching active ones.
Check your autoload total after cleanup. In phpMyAdmin, run: SELECT SUM(LENGTH(option_value)) FROM wp_options WHERE autoload='yes'; — this returns the autoloaded payload in bytes. The target is under 800,000 (800 KB). If the result is still above that after transient cleanup, a plugin is writing large data with autoload=yes. The Query Monitor plugin's Options panel shows which option names are largest, pointing you to the plugin that needs to be removed or replaced. The easiest way to optimize your WordPress database autoload total is to remove the offending plugin, then rerun the cleanup.
For a broader look at how plugin selection and website performance optimization fit together, the performance guide covers the full stack — caching, image compression, CDN — in one place. Database performance is the foundation; those other layers multiply its effect.
Why database maintenance is urgent for SA WordPress businesses
Database bloat's most direct business consequence is a slower time-to-first-byte (TTFB). Google's 2018 mobile page speed research found that 53% of mobile site visitors abandon a page that takes longer than three seconds to load — a threshold that TTFB directly influences. In South Africa, where the majority of web traffic arrives on mobile devices, TTFB is the server-side factor your database and hosting directly control, independent of image sizes or script loading order. Regular WordPress database maintenance is therefore more impactful on shared-hosting SA sites — where database memory is pooled — than on the same site running on a dedicated server.
Running WooCommerce amplifies this further. WooCommerce adds its own custom tables — including wc_order_items, wc_order_itemmeta, and wc_customer_lookup — and writes order metadata at high frequency. A busy SA ecommerce store with a year of order history and no database maintenance accumulates a volume of metadata rows that shows up first in admin dashboard speed and report generation times, then in front-end checkout query latency.
The connection to your broader site infrastructure is covered in the website speed optimisation guide for South Africa, which covers the full remediation sequence. A well-maintained WordPress database means the caching layer and CDN are accelerating queries that are already lean — not compensating for underlying bloat.
Want a performance audit before committing to any work?
We review your Core Web Vitals, TTFB, and database autoload size — and tell you what to fix first. No obligation.
Request a Performance AuditWhy South African Businesses Choose Growth Pulse Media
Growth Pulse Media was founded by Dirk van Greuning, who built and scaled a South African ecommerce operation before starting the agency. That operator background shapes how technical maintenance work like WordPress database optimization is evaluated — the question is always whether the cleanup sequence will move a number that matters for the business: TTFB, checkout completion rate, or admin time spent waiting for reports.
All work is executed in-house. GPM carries a limited client load so that every engagement gets senior-level attention throughout — including the recurring maintenance work that keeps sites fast between redesigns. Our web design service includes database optimization as a scheduled part of ongoing maintenance, not an add-on billed separately when a site becomes noticeably slow.
If your WordPress site is running slower than it was six to twelve months ago, that is a diagnosable, fixable problem — not a reason to rebuild. We work with SA businesses on website maintenance contracts where database cleanup and performance checks run on a quarterly schedule.
Who This Guide Is NOT For
Sites on static site generators. Gatsby, Hugo, Next.js, and similar static frameworks compile pages to files at build time — there is no live database. WordPress database optimization is irrelevant to this architecture.
Sites on managed WordPress platforms with automatic optimization built in. Some managed WordPress hosts disable post revisions by default and automatically handle transient cleanup. Check your host's documentation before running a manual cleanup that duplicates what the platform already does — particularly relevant if you are on WP Engine or a similar managed provider.
Businesses whose primary performance problem is the hosting plan itself. If your TTFB is consistently above 600ms after database cleanup and caching are both in place, the constraint is likely server CPU or RAM — a database cleanup helps at the margin, but moving to a better-resourced hosting plan has more impact. Database optimization and hosting quality are complementary, not interchangeable.
Sites without a recent backup. Any database operation — including OPTIMIZE TABLE — can expose underlying table corruption. Take a full backup before starting, or have a developer run the cleanup against a staging environment first. Restoring from a pre-cleanup backup is straightforward; discovering corruption mid-cleanup on a live site is not.
Frequently Asked Questions
How often should I run WordPress database optimization?
For most SA business sites, monthly transient and revision cleanup combined with quarterly OPTIMIZE TABLE is a practical schedule. High-volume WooCommerce stores — processing more than a few hundred orders per month — benefit from monthly optimization across all five tasks, because order metadata accumulates faster. WP-Optimize's free version handles all five cleanup tasks on demand — automatic scheduling is a premium feature, but running the tasks manually takes under five minutes and can be triggered by a recurring calendar reminder.
Will WordPress database optimization break my site?
A correctly executed cleanup does not break a healthy site. The risk arises when tables are already corrupted — optimization on a corrupted table can fail and surface the underlying corruption. Always take a full database backup before running any optimization — WP-Optimize includes a built-in backup step before cleanup runs. If a cleanup fails and the site shows errors, restoring from the pre-cleanup backup returns the site to its previous state without data loss.
What is a safe autoloaded data size for WordPress?
Both the WordPress official documentation and WP Engine set 800 KB as the target for total autoloaded data. After running a transient cleanup, use phpMyAdmin to run SELECT SUM(LENGTH(option_value)) FROM wp_options WHERE autoload='yes'; to confirm the autoload total has dropped below the 800 KB threshold.
Does WordPress database optimization improve SEO?
Database optimization improves server response time, which is a component of Core Web Vitals — specifically, TTFB contributes to Largest Contentful Paint (LCP). Google's page experience guidance confirms Core Web Vitals are used as a ranking signal. On a site where TTFB is high enough to push LCP outside the "Good" threshold, database cleanup can shift scores into a range that removes a ranking disadvantage. It also reduces the time Googlebot spends waiting on each crawled URL, which indirectly helps large sites get more pages indexed per crawl budget.
Can I use WP-Optimize on a WooCommerce site?
Yes, and WooCommerce sites benefit the most from regular database maintenance. WooCommerce adds its own custom tables — wc_order_items, wc_order_itemmeta, wc_customer_lookup, and others — and writes order metadata at high frequency. WP-Optimize targets the standard WordPress tables (wp_posts, wp_postmeta, wp_options, wp_comments) including orphaned metadata. For WooCommerce-specific order table maintenance, the WooCommerce documentation covers additional cleanup steps for the wc_ prefix tables once the core WordPress tables are clean.
Want Expert Help With WordPress Database Optimization?
Growth Pulse Media builds search dominance for South African businesses — SEO, paid media, and lead generation executed in-house by operators with real SA market experience. No obligation.
Get a No-Obligation Consultation

