{"id":136,"date":"2026-04-03T12:45:00","date_gmt":"2026-04-03T11:45:00","guid":{"rendered":"https:\/\/www.webfort.co.uk\/blog\/?p=136"},"modified":"2026-03-28T20:18:58","modified_gmt":"2026-03-28T20:18:58","slug":"optimize-wordpress-database-performance","status":"publish","type":"post","link":"https:\/\/www.webfort.co.uk\/blog\/optimize-wordpress-database-performance\/","title":{"rendered":"How to Optimize Your WordPress Database for Better Performance"},"content":{"rendered":"<p>If you want to optimize your WordPress database, you&#8217;re probably noticing your site getting slower over time. It&#8217;s not your hosting getting worse or your plugins changing. It&#8217;s your database filling up with data WordPress doesn&#8217;t need any more.<\/p>\n<p>Every page revision, spam comment, expired transient, and orphaned metadata adds rows to your database. After a year of running a WordPress site, your database might contain ten times more data than it needs. All of that extra weight slows down every page load.<\/p>\n<p>The fix takes about fifteen minutes and the difference is often immediate. This guide walks through exactly what to clean up, how to do it safely, and how to stop the bloat from coming back.<\/p>\n<h3>What&#8217;s in This Post<\/h3>\n<ul>\n<li><a href=\"#why-databases-slow\">Why WordPress Databases Get Slow<\/a><\/li>\n<li><a href=\"#what-to-clean\">What You Can Safely Remove<\/a><\/li>\n<li><a href=\"#backup-first\">Back Up Your Database First<\/a><\/li>\n<li><a href=\"#plugin-method\">Method 1: Using a Plugin (Recommended)<\/a><\/li>\n<li><a href=\"#phpmyadmin-method\">Method 2: Using phpMyAdmin<\/a><\/li>\n<li><a href=\"#post-revisions\">Controlling Post Revisions<\/a><\/li>\n<li><a href=\"#autoload\">The Autoloaded Data Problem<\/a><\/li>\n<li><a href=\"#scheduled-cleanup\">Setting Up Automatic Cleanup<\/a><\/li>\n<li><a href=\"#how-to-measure\">How to Measure the Difference<\/a><\/li>\n<li><a href=\"#final-thoughts\">Final Thoughts<\/a><\/li>\n<\/ul>\n<h2 id=\"why-databases-slow\">Why WordPress Databases Get Slow<\/h2>\n<p>WordPress stores almost everything in a MySQL database: your posts, pages, comments, settings, plugin data, theme options, and user information. Every time you save a draft, WordPress creates a revision. Every spam comment that arrives gets stored. Every plugin that saves temporary data (transients) adds rows.<\/p>\n<p>Over months and years, this accumulates. A database that started at 5MB might grow to 200MB, with most of that being data nobody will ever use again. The database engine still has to search through all of it every time someone loads a page.<\/p>\n<p>Common database bloat sources:<\/p>\n<ul>\n<li><strong>Post revisions<\/strong> \u2014 WordPress saves every edit as a separate revision. A post edited 50 times has 50 revisions stored in the database.<\/li>\n<li><strong>Spam and trashed comments<\/strong> \u2014 Deleted and spam comments sit in the database until explicitly purged.<\/li>\n<li><strong>Expired transients<\/strong> \u2014 Temporary cached data from plugins that should have been deleted but wasn&#8217;t.<\/li>\n<li><strong>Orphaned metadata<\/strong> \u2014 Data left behind by plugins you&#8217;ve deactivated or deleted.<\/li>\n<li><strong>Pingbacks and trackbacks<\/strong> \u2014 Outdated notification data from other sites linking to yours.<\/li>\n<li><strong>Table overhead<\/strong> \u2014 Fragmentation from repeated inserts and deletes, similar to defragmenting a hard drive.<\/li>\n<\/ul>\n<h2 id=\"what-to-clean\">What You Can Safely Remove<\/h2>\n<p>Not everything in the database should be touched. Some data is critical (your actual posts, pages, and settings). Other data is disposable.<\/p>\n<p><strong>Safe to remove:<\/strong><\/p>\n<ul>\n<li>Post revisions (your published content stays, only edit history is removed)<\/li>\n<li>Auto-drafts (unsaved drafts WordPress creates automatically)<\/li>\n<li>Trashed posts and pages<\/li>\n<li>Spam comments and trashed comments<\/li>\n<li>Expired transients<\/li>\n<li>Trackbacks and pingbacks<\/li>\n<li>Table overhead\/fragmentation<\/li>\n<\/ul>\n<p><strong>Leave alone:<\/strong><\/p>\n<ul>\n<li>Published posts, pages, and their current content<\/li>\n<li>Active comments<\/li>\n<li>User accounts and roles<\/li>\n<li>Plugin settings and configuration<\/li>\n<li>WooCommerce orders and customer data<\/li>\n<\/ul>\n<h2 id=\"backup-first\">Back Up Your Database First<\/h2>\n<p>Before changing anything, take a backup. If something goes wrong, you want to be able to restore everything to exactly how it was five minutes ago.<\/p>\n<p>Most managed hosting providers (including Webfort) run daily automated backups. But for database changes, it&#8217;s worth taking a manual backup immediately before you start. You can do this through your hosting control panel&#8217;s backup tool or by exporting the database via phpMyAdmin.<\/p>\n<p>If your host doesn&#8217;t provide easy backups, that&#8217;s a red flag worth taking seriously. We covered what good hosting should include in our <a href=\"\/blog\/things-to-check-before-choosing-web-host\/\">hosting checklist guide<\/a>.<\/p>\n    <div class=\"webfort-cta\" style=\"background: rgba(255, 255, 255, 0.03); border: 1px solid rgba(255, 255, 255, 0.1); border-radius: 20px; padding: 40px 36px; margin: 48px 0; text-align: center; font-family: 'Outfit', system-ui, sans-serif; position: relative; overflow: hidden;\">\n      <!-- Subtle glow accents -->\n      <div style=\"position: absolute; top: -100px; right: -100px; width: 300px; height: 300px; background: radial-gradient(circle, rgba(200, 255, 0, 0.08) 0%, transparent 70%); pointer-events: none;\"><\/div>\n      <div style=\"position: absolute; bottom: -100px; left: -100px; width: 300px; height: 300px; background: radial-gradient(circle, rgba(200, 255, 0, 0.05) 0%, transparent 70%); pointer-events: none;\"><\/div>\n      \n      <!-- Content -->\n      <div style=\"position: relative; z-index: 1;\">\n        <h3 style=\"font-size: 28px; font-weight: 800; color: #ffffff; margin: 0 0 16px 0; line-height: 1.2;\">Looking for fast, reliable UK hosting?<\/h3>\n        <p style=\"font-size: 17px; color: rgba(255, 255, 255, 0.6); margin: 0 0 28px 0; line-height: 1.6; max-width: 560px; margin-left: auto; margin-right: auto;\">Our plans start from <strong style=\"color: #ffffff\">\u00a34.99\/month<\/strong> with everything included: SSL, backups, email, and 24\/7 support.<\/p>\n        <a href=\"https:\/\/www.webfort.co.uk\/web-hosting\/\" style=\"display: inline-block; background: #c8ff00; color: #0a0f1c; font-family: 'Outfit', system-ui, sans-serif; font-weight: 600; font-size: 16px; padding: 14px 36px; border-radius: 100px; text-decoration: none; box-shadow: 0 4px 16px rgba(200, 255, 0, 0.2); transition: all 0.2s ease;\">View Hosting Plans \u2192<\/a>\n      <\/div>\n    <\/div>\n    \n<h2 id=\"plugin-method\">Method 1: Using a Plugin (Recommended)<\/h2>\n<p>The safest way to clean your database is with a dedicated plugin. Two reliable options:<\/p>\n<h3>WP-Optimize<\/h3>\n<p><a href=\"https:\/\/wordpress.org\/plugins\/wp-optimize\/\" target=\"_blank\" rel=\"noopener nofollow\">WP-Optimize<\/a> is a free plugin that handles database cleanup, image compression, and caching. For database optimization:<\/p>\n<ol>\n<li>Install and activate WP-Optimize from the WordPress plugin directory<\/li>\n<li>Go to <strong>WP-Optimize \u2192 Database<\/strong><\/li>\n<li>Review the list of optimizations (revisions, drafts, spam comments, transients, etc.)<\/li>\n<li>Tick the items you want to clean<\/li>\n<li>Click <strong>Run all selected optimizations<\/strong><\/li>\n<\/ol>\n<p>The plugin shows you exactly how many items will be removed and how much space you&#8217;ll save before you confirm anything.<\/p>\n<figure style=\"max-width:100%\"><img decoding=\"async\" src=\"https:\/\/images.pexels.com\/photos\/577585\/pexels-photo-577585.jpeg?auto=compress&#038;cs=tinysrgb&#038;w=800\" alt=\"Optimizing WordPress database for better performance\" style=\"max-width:100%;height:auto\" \/><figcaption>Database optimization is one of the quickest wins for WordPress speed.<\/figcaption><\/figure>\n<h3>Advanced Database Cleaner<\/h3>\n<p>For more granular control, <a href=\"https:\/\/wordpress.org\/plugins\/developer\/developer-developer\/\" target=\"_blank\" rel=\"noopener nofollow\">Advanced Database Cleaner<\/a> lets you inspect individual tables and identify data left behind by deleted plugins. It&#8217;s particularly useful for finding orphaned tables that other cleanup plugins miss.<\/p>\n<h2 id=\"phpmyadmin-method\">Method 2: Using phpMyAdmin<\/h2>\n<p>If you prefer working directly with the database, phpMyAdmin (available through most hosting control panels) lets you optimize tables manually.<\/p>\n<ol>\n<li>Log into your hosting control panel and open phpMyAdmin<\/li>\n<li>Select your WordPress database from the left sidebar<\/li>\n<li>Click <strong>Check All<\/strong> to select all tables<\/li>\n<li>From the &#8220;With selected&#8221; dropdown, choose <strong>Optimize table<\/strong><\/li>\n<li>Click <strong>Go<\/strong><\/li>\n<\/ol>\n<p>This defragments your tables and reclaims wasted space. It&#8217;s the equivalent of the &#8220;optimize tables&#8221; button in WP-Optimize, but done manually.<\/p>\n<p>To delete post revisions via SQL (advanced):<\/p>\n<pre><code>DELETE FROM wp_posts WHERE post_type = 'revision';<\/code><\/pre>\n<p>Only run SQL queries if you&#8217;re comfortable with databases and have a backup ready. One wrong query can break your site.<\/p>\n<h2 id=\"post-revisions\">Controlling Post Revisions<\/h2>\n<p>WordPress saves unlimited revisions by default. If you edit a blog post 30 times, you have 30 revisions stored permanently. For most sites, keeping the last 3-5 revisions is plenty.<\/p>\n<p>Add this line to your <code>wp-config.php<\/code> file to limit revisions:<\/p>\n<pre><code>define('WP_POST_REVISIONS', 5);<\/code><\/pre>\n<p>This keeps the 5 most recent revisions for each post and prevents the revision count from growing indefinitely. You can set it to <code>false<\/code> to disable revisions entirely, but keeping a few is safer in case you need to undo a recent change.<\/p>\n<h2 id=\"autoload\">The Autoloaded Data Problem<\/h2>\n<p>This is the most overlooked database performance issue. WordPress has an <code>options<\/code> table where plugins store settings. Some of these options are marked as &#8220;autoload&#8221;, meaning WordPress loads them on every single page request whether they&#8217;re needed or not.<\/p>\n<p>Plugins that store large amounts of data in autoloaded options can add hundreds of milliseconds to every page load. To check your autoloaded data size, run this in phpMyAdmin:<\/p>\n<pre><code>SELECT SUM(LENGTH(option_value)) AS autoload_size \nFROM wp_options \nWHERE autoload = 'yes';<\/code><\/pre>\n<p>If the result is over 1MB, you have autoload bloat. Common culprits are old caching plugins, analytics plugins that store data locally, and social sharing plugins. The fix is usually deactivating and deleting the problem plugin, which removes its autoloaded data.<\/p>\n<h2 id=\"scheduled-cleanup\">Setting Up Automatic Cleanup<\/h2>\n<p>Manual optimization is a one-time fix. Without automatic cleanup, the bloat returns within months.<\/p>\n<p>WP-Optimize includes a scheduler. Go to <strong>WP-Optimize \u2192 Settings<\/strong> and enable automatic cleanup on a weekly or fortnightly schedule. Set it to run during low-traffic hours (early morning) to avoid any brief performance impact during optimization.<\/p>\n<p>A reasonable automatic schedule:<\/p>\n<ul>\n<li>Clean post revisions (keep last 5): weekly<\/li>\n<li>Remove auto-drafts: weekly<\/li>\n<li>Clear expired transients: weekly<\/li>\n<li>Optimize tables: fortnightly<\/li>\n<li>Remove spam\/trashed comments: weekly<\/li>\n<\/ul>\n<p>Combined with the <code>WP_POST_REVISIONS<\/code> limit in wp-config.php, this keeps your database lean indefinitely.<\/p>\n<h2 id=\"how-to-measure\">How to Measure the Difference<\/h2>\n<p>Before running any optimization, test your site speed so you can compare the results. Three ways to measure:<\/p>\n<ol>\n<li><strong><a href=\"https:\/\/pagespeed.web.dev\/\" target=\"_blank\" rel=\"noopener nofollow\">Google PageSpeed Insights<\/a><\/strong> \u2014 Free, tests both mobile and desktop. Look at the Time to First Byte (TTFB) metric specifically, as that&#8217;s most affected by database performance.<\/li>\n<li><strong>Query Monitor plugin<\/strong> \u2014 Install the free <a href=\"https:\/\/wordpress.org\/plugins\/query-monitor\/\" target=\"_blank\" rel=\"noopener nofollow\">Query Monitor<\/a> plugin to see exactly how many database queries each page makes and how long they take. Run this before and after optimization.<\/li>\n<li><strong>Your hosting dashboard<\/strong> \u2014 Some hosts show server response times. Check if yours does.<\/li>\n<\/ol>\n<p>Typical results from database optimization: 20-40% reduction in TTFB and 10-30% fewer database queries per page. For sites with heavily bloated databases, the improvement can be even larger. For more on what speed metrics to target, see our <a href=\"\/blog\/why-your-website-speed-matters-more-than-you-think-in-2026\/\">guide to website speed in 2026<\/a>.<\/p>\n<h2 id=\"final-thoughts\">Final Thoughts<\/h2>\n<p>Database optimization is one of the most effective and least discussed WordPress performance fixes. It takes fifteen minutes, the risk is low (with a backup), and the results are often noticeable immediately.<\/p>\n<p>Clean up the bloat, limit revisions, set up automatic maintenance, and your database stays fast long-term. It&#8217;s the kind of maintenance that <a href=\"\/blog\/litespeed-cache-wordpress-guide\/\">pairs well with server-level caching<\/a> to keep your WordPress site running at its best.<\/p>\n<p>If your site is still slow after optimizing the database, the issue might be your hosting rather than your WordPress setup. Slow servers, oversold shared hosting, or distant data centres all affect performance regardless of how clean your database is. Our <a href=\"\/blog\/shared-vs-vps-vs-dedicated-hosting\/\">guide to hosting types<\/a> explains the differences. And our <a href=\"\/free-website-check\/\">free Website MOT tool<\/a> can help identify whether hosting performance is the bottleneck.<\/p>\n    <div class=\"webfort-cta\" style=\"background: rgba(255, 255, 255, 0.03); border: 1px solid rgba(255, 255, 255, 0.1); border-radius: 20px; padding: 40px 36px; margin: 48px 0; text-align: center; font-family: 'Outfit', system-ui, sans-serif; position: relative; overflow: hidden;\">\n      <!-- Subtle glow accents -->\n      <div style=\"position: absolute; top: -100px; right: -100px; width: 300px; height: 300px; background: radial-gradient(circle, rgba(200, 255, 0, 0.08) 0%, transparent 70%); pointer-events: none;\"><\/div>\n      <div style=\"position: absolute; bottom: -100px; left: -100px; width: 300px; height: 300px; background: radial-gradient(circle, rgba(200, 255, 0, 0.05) 0%, transparent 70%); pointer-events: none;\"><\/div>\n      \n      <!-- Content -->\n      <div style=\"position: relative; z-index: 1;\">\n        <h3 style=\"font-size: 28px; font-weight: 800; color: #ffffff; margin: 0 0 16px 0; line-height: 1.2;\">Is your website holding your business back?<\/h3>\n        <p style=\"font-size: 17px; color: rgba(255, 255, 255, 0.6); margin: 0 0 28px 0; line-height: 1.6; max-width: 560px; margin-left: auto; margin-right: auto;\">Run our free 30-second health check - no signup required. Check speed, security, and SEO issues instantly.<\/p>\n        <a href=\"https:\/\/www.webfort.co.uk\/free-website-check\/\" style=\"display: inline-block; background: #c8ff00; color: #0a0f1c; font-family: &#039;Outfit&#039;, system-ui, sans-serif; font-weight: 600; font-size: 16px; padding: 14px 36px; border-radius: 100px; text-decoration: none; box-shadow: 0 4px 16px rgba(200, 255, 0, 0.2); transition: all 0.2s ease;\">Check My Website \u2192<\/a>\n      <\/div>\n    <\/div>\n    \n","protected":false},"excerpt":{"rendered":"<p>If you want to optimize your WordPress database, you&#8217;re probably noticing your site getting slower over time. It&#8217;s not your hosting getting worse or your plugins changing. It&#8217;s your database filling up with data WordPress doesn&#8217;t need any more. Every page revision, spam comment, expired transient, and orphaned metadata adds rows to your database. After [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":135,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[2,3],"tags":[56,57,6,29,5],"class_list":["post-136","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-wordpress","category-performance","tag-database","tag-optimization","tag-page-speed","tag-wordpress","tag-wordpress-performance"],"_links":{"self":[{"href":"https:\/\/www.webfort.co.uk\/blog\/wp-json\/wp\/v2\/posts\/136","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.webfort.co.uk\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.webfort.co.uk\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.webfort.co.uk\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.webfort.co.uk\/blog\/wp-json\/wp\/v2\/comments?post=136"}],"version-history":[{"count":1,"href":"https:\/\/www.webfort.co.uk\/blog\/wp-json\/wp\/v2\/posts\/136\/revisions"}],"predecessor-version":[{"id":137,"href":"https:\/\/www.webfort.co.uk\/blog\/wp-json\/wp\/v2\/posts\/136\/revisions\/137"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.webfort.co.uk\/blog\/wp-json\/wp\/v2\/media\/135"}],"wp:attachment":[{"href":"https:\/\/www.webfort.co.uk\/blog\/wp-json\/wp\/v2\/media?parent=136"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.webfort.co.uk\/blog\/wp-json\/wp\/v2\/categories?post=136"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.webfort.co.uk\/blog\/wp-json\/wp\/v2\/tags?post=136"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}