How To Clean Up Your WordPress Database

By Database, Site Speed, WordPress No Comments

Whether you’re a beginner or have limited experience in managing databases, we’ve got you covered. In this guide, we’ll walk you through simple and efficient methods to clean up your WordPress database. We’ll explore both plugin and non-plugin approaches, providing you with options based on your comfort level. So, let’s dive in and learn how to optimize your database for improved site performance and a smoother user experience.

What Slows Down WordPress Sites? 

Several factors can contribute to a WordPress site’s slowdown. Here are some common culprits:

  1. Hosting Environment: The choice of hosting provider and hosting plan can significantly impact site speed. Shared hosting, where multiple websites share server resources, may result in slower performance compared to dedicated or managed hosting. Ensure that your hosting environment is optimized for WordPress and offers sufficient resources for your website’s needs.
  2. Bloated or Inefficient Themes: Some WordPress themes come with excessive features, complex code, or poorly optimized elements that can slow down your site. Opt for lightweight, well-coded themes that prioritize performance.
  3. Plugins: While plugins extend functionality, having too many or poorly coded plugins can impact site speed. Each active plugin adds overhead to the page load process. Regularly review your plugin list and remove unnecessary or outdated plugins. Opt for well-maintained and optimized plugins.
  4. Large Media Files: Uploading and displaying large images or videos without optimization can slow down your site. Resize and compress images before uploading them, and consider using lazy loading techniques to load media only when it’s needed.
  5. Lack of Caching: Caching allows your website to serve static versions of pages instead of generating them dynamically with each request. Without caching, your site may be slower, especially during high traffic periods. Implement a caching mechanism, such as a caching plugin or server-level caching, to improve site speed.
  6. Excessive HTTP Requests: Each resource (CSS, JavaScript, images, etc.) loaded by your site requires a separate HTTP request. Having too many external files or poorly optimized code can increase the number of requests, slowing down page load times. Minify and combine CSS and JavaScript files, and consider using a CDN to offload some requests.
  7. Database Issues: A poorly optimized or bloated database can impact site performance. Regularly optimize your database, remove unnecessary data, and consider implementing a caching mechanism to reduce database queries.
  8. Poorly Coded Customizations: Custom code snippets or modifications to themes and plugins can introduce performance issues if not implemented efficiently. Ensure that customizations are well-coded and optimized to minimize any negative impact on site speed.
  9. External Scripts and Services: Integrating third-party scripts, such as social media widgets, analytics trackers, or ad networks, can introduce additional delays due to external requests or slow-loading scripts. Evaluate and limit the number of external scripts used, and optimize their implementation for performance.
  10. Traffic Overload: A sudden increase in website traffic can overload server resources and slow down your site. Consider using a content delivery network (CDN) or scaling up your hosting resources to handle high traffic loads.

To improve site speed, regularly monitor and optimize these areas, keeping your WordPress installation, themes, plugins, and content optimized for performance.

How Does My Database Slow Down My Site? 

If you suspect that your database is slowing down your WordPress site, there are several signs you can look out for. Here are some indicators that your database might be causing performance issues:

  1. Slow Page Load Times: If your website takes a long time to load, it could be due to a slow database. When WordPress retrieves data from the database, such as posts, pages, or comments, a slow database can significantly impact the page load speed.
  2. High CPU Usage: If your website’s server is experiencing high CPU usage, it might indicate that the database is being overworked. You can check the server logs or use server monitoring tools to determine CPU usage.
  3. Slow Database Queries: WordPress relies heavily on database queries to retrieve and display content. If your database queries are slow, it can cause delays in rendering pages. You can use plugins like Query Monitor or the Debug Bar plugin to analyze the performance of your database queries.
  4. Database Connection Errors: If you encounter database connection errors, such as “Error establishing a database connection,” it could be a sign that the database server is overloaded or experiencing performance issues.
  5. High TTFB (Time To First Byte): TTFB refers to the time taken for the server to start sending data in response to a request. A slow database can contribute to high TTFB values, resulting in slower overall page loading times.
  6. Increased Database Size: As your WordPress site grows, the size of your database can increase significantly. If your database becomes large and bloated with unnecessary data, it can impact its performance. Regular maintenance and optimization of your database can help alleviate this issue.

Use A Plugin To Clean Up Your Database

If you’re new to managing databases or prefer a straightforward approach, using a plugin to clean up your WordPress database is the way to go. In this section, we’ll guide you through the process step by step, ensuring that even those without prior experience can follow along easily. Our tutorial will provide clear instructions and explanations, making it accessible to everyone. Let’s explore how you can efficiently clean up your database using a plugin and optimize your WordPress site for better performance.

Step 1 – Backup Your Site

Backing up your website before cleaning up the database provides a safety net, safeguards your data integrity, allows for easy rollback, facilitates testing and development, and enables effective disaster recovery. It is a precautionary measure that ensures you can restore your site to a previous working state if any issues occur during the database cleanup process.

I recommend backing up your site through your hosting provider if that is included in your hosting. These providers, among others, offer free backups: WP Engine, Siteground, Bluehost, InterSever, Hostinger, A2 Hosting, TMDHosting, Hostinger, ACCU, Dreamhost, Namecheap, etc. Many other providers also have backups as an add-on you can purchase.

If your hosting does not include backups, you will need to use a plugin for this. UpdraftPlus WordPress Backup Plugin works well for this. To create a backup of your WordPress site using the UpdraftPlus plugin, follow these steps:

  1. Install and Activate the UpdraftPlus Plugin:
    • Log in to your WordPress dashboard.
    • Go to “Plugins” > “Add New.”
    • Search for “UpdraftPlus” in the search bar.
    • Click “Install Now” next to the UpdraftPlus plugin.
    • After installation, click “Activate” to activate the plugin.
  2. Configure UpdraftPlus Settings:
    • Once activated, you’ll find the UpdraftPlus plugin under “Settings” in your WordPress dashboard.
    • Click on “UpdraftPlus Backups” to access the plugin’s settings.
    • In the “Settings” tab, you can choose backup schedule options, select files and database to include in the backup, and set up remote storage options (such as Dropbox, Google Drive, or FTP).
    • Adjust the settings according to your preferences.
  3. Create a Manual Backup:
    • To create a backup manually, go to the “Current Status” tab in the UpdraftPlus settings.
    • Click the “Backup Now” button to initiate the backup process.
    • UpdraftPlus will start creating a backup of your website’s files and database. The time it takes will depend on the size of your site.
  4. Verify and Download the Backup Files:
    • After the backup process completes, you’ll see the backup sets listed on the “Existing Backups” tab.
    • You can see the date, time, and size of each backup set.
    • To download the backup files to your computer, click on the “Download” button next to the backup set you want to retrieve.

That’s it! You have successfully created a backup of your WordPress site using the UpdraftPlus plugin. Remember to store your backup files securely, preferably in multiple locations or using remote storage options provided by UpdraftPlus, to ensure their safety.

Step 2 – Remove Any plugins That Are Not Being Used

Removing unused plugins enhances performance, improves security, simplifies maintenance, streamlines the user experience, reduces conflicts, and optimizes resource consumption. Regularly auditing and removing plugins that are not actively used ensures a leaner, more efficient WordPress site.

Within your WP Admin Dashboard, click on Plugins, then choose the inactive tab. Click delete to remove any plugins you don’t plan on using.

Step 3 – Install WP-Optimize – Cache, Clean, Compress

WP-Optimize is a highly regarded WordPress plugin that offers a user-friendly interface and powerful database optimization features. It efficiently cleans up and optimizes your database, removing unnecessary data and improving overall performance. With scheduled cleanups, customizable options, and compatibility with multisite installations, WP-Optimize streamlines database management. By reducing database size, enhancing query execution, and integrating well with other plugins, it significantly improves site speed and supports a smooth user experience. Regular updates and support ensure the plugin’s reliability and effectiveness, making WP-Optimize a valuable tool for optimizing your WordPress site’s performance.

  1. Within your WP Admin Dashboard, click on Plugins, then Add New.
  2. Search for WP-Optimize – Cache, Clean, Compress in the search field on the right.
  3. Click Install Now, then Activate
  4. In the WP Admin Dashboard, you will now see WP-Optimize in the left menu (probably toward the bottom). Click on it. You will be brought to the Optimizations screen within WP Optimize.
  5. Click Run all selected optimizations. When this finishes you will see that the dialog below each checked optimization has been updated to let you know what was deleted.
  6. Next, click the Tables tab. Look for any labeled [not installed]. There will be a list of the plugins that were using these tables in blue. (To ensure you are deleting a plugin that you have removed, you can click on the blue plugin link to get more details and make sure you recognize the plugin.) Click the Remove button to the right.
  7. Next, click the Settings tab. Here you can schedule future clean up and optimizations. I’d recommend sticking with the default settings (Clean all post revisions, Remove auto-draft posts, Remove trashed posts & Remove spam and trashed comments) and scheduling these weekly, but you can set these to whatever you are comfortable with. 

Use phpMyAdmin to clean up your database

If you have experience working with MySQL and feel comfortable navigating its intricacies, using phpMyAdmin to clean up your WordPress database is an option worth considering. This section is specifically intended for users who are well-versed in managing databases through phpMyAdmin. We’ll provide insights and guidance on how to efficiently clean up your database using this powerful tool. However, please note that if you’re not familiar with MySQL or phpMyAdmin, it’s best to seek assistance from an experienced professional to avoid potential data loss or other issues. Let’s explore the process of cleaning up your database using phpMyAdmin for those who are proficient in database management.


Step 1 – Backup your site

Ensuring the safety of your website data is crucial before making any modifications to your database. It’s highly recommended to create a backup before making any changes, and it’s even advisable to create backups at different stages of the process to minimize the risk of losing any crucial data. By having regular backups in place, you can easily restore your site to a previous working state if any issues arise during the cleaning process. Taking these precautionary measures will provide you with peace of mind and a safety net to fall back on, should anything unexpected occur. 


Step 2 – Clean Up Orphaned Data

Since MySQL is a relational database system, when a post is deleted it often leaves behind data in other tables. Cleaning up orphaned data reduces the size of your database, resulting in faster queries, improved disk space usage, optimized indexing, enhanced backup and restoration processes, reduced server load, and effective database maintenance. These benefits collectively contribute to better performance and a smoother user experience for your WordPress site.

  1. Open phpMyAdmin
  2. Click on the main table for your wordpress site wp_sitename
  3. Click on SQL and enter one of the suggested commonly used snippets into the box and click Go.

Commonly Used Snippets

By addressing specific areas such as orphaned post meta, comment meta, revisions, session data, expired transients, unassociated tags, pingbacks, and trackbacks, you’ll be able to remove unnecessary data and enhance your website’s performance. 

Check for Orphaned Post Meta
SELECT COUNT(pm.meta_id) as row_count FROM wp_postmeta pm LEFT JOIN wp_posts wp ON wp.ID = pm.post_id WHERE wp.ID IS NULL;

Delete Orphaned Post Meta
DELETE pm FROM wp_postmeta pm LEFT JOIN wp_posts wp ON wp.ID = pm.post_id WHERE wp.ID IS NULL;

Check for Orphaned Comment Meta

SELECT COUNT(*) as row_count FROM wp_commentmeta WHERE comment_id NOT IN (SELECT comment_id FROM wp_comments);

Delete Orphaned Comment Meta

DELETE FROM wp_commentmeta WHERE comment_id NOT IN (SELECT comment_id FROM wp_comments);

Delete Revisions

DELETE FROM wp_posts WHERE post_type = “revision”;

Check for Session Data

SELECT * FROM `wp_options` WHERE `option_name` LIKE ‘_wp_session_%’;

Delete Session Data

DELETE FROM `wp_options` WHERE `option_name` LIKE ‘_wp_session_%’;

Delete Expired Transients

DELETE FROM `wp_options` WHERE `option_name` LIKE (‘%_transient_%’);

Delete Unassociated Tags

DELETE FROM wp_terms WHERE term_id IN (SELECT term_id FROM wp_term_taxonomy WHERE count = 0 );

DELETE FROM wp_term_taxonomy WHERE term_id not IN (SELECT term_id FROM wp_terms);

DELETE FROM wp_term_relationships WHERE term_taxonomy_id not IN (SELECT term_taxonomy_id FROM wp_term_taxonomy);

Delete Pingbacks and Trackbacks

DELETE FROM wp_comments WHERE comment_type = ‘pingback’;

DELETE FROM wp_comments WHERE comment_type = ‘trackback’;

Step 3 – Optimize Your Database

You also can free up local storage to improve performance by using the Optimize Table command. By utilizing the Optimize Table command, you can enhance the overall efficiency of your WordPress site. 

  1. Open phpMyAdmin
  2. Click on the main table for your wordpress site wp_sitename
  3. Click “Check all” then choose “Optimize table” from the drop down menu.
  4. You will receive confirmation letting you know the process is complete.


Regularly cleaning up your database offers numerous benefits for your WordPress site. It reduces the size of your database, optimizes query performance, enhances disk space usage, improves backup and restoration processes, and reduces server load. These optimizations work together to make your site faster, more efficient, and provide a smoother user experience.

Cleaning up your WordPress database is essential for maintaining a high-performing website. By following the steps outlined in this article, you can easily optimize your database and improve the speed and efficiency of your site.

It’s important to remember to always create backups before performing any database operations. Additionally, exercise caution when making changes to your database and consult with professionals if you have any uncertainties. By practicing proper database maintenance, you can ensure that your WordPress site operates at its best.