How to clear the database in wordpress

print · Время на чтение: 9мин · - · Опубликовано · Обновлено

playListen to this article

How to clear the database in wordpressDo you want a fast WordPress site? If it is true, you need to clear the wordpress databaseby deleting unnecessary data. Cleaning up the WordPress database is an important maintenance task, which will reduce the loading time of pages on your site. It should be done in conjunction with other performance enhancements such as page caching, image optimization, Javascript deferral, and stripping unused CSS styles.

The WordPress database stores website content in posts, pages, and other types of posts. It also stores comments, links, portfolio items, form entries, plugin settings, theme settings, media settings, and more.

Unfortunately, if not taken care of, WordPress databases quickly become bloated with data that is no longer required. This increases the size of the database and the time it takes to retrieve information, which inevitably slows down your site.

The goal of WordPress database optimization is to remove unnecessary data so that your site runs more efficiently and loads pages faster.

Let's take a closer look at why WordPress databases grow in size and then take a look at how you can clean up your WordPress database.

The content of the article:

Why are WordPress databases growing in size?

When you install WordPress, a WordPress database is created with 11 main tables. These tables will store information such as your website settings, posts, pages, comments, links, and users.

Whenever you update your website and add new content, the WordPress database will grow in size. For example:

  • Add new page - to wp_posts table a new line will be added to hold the content of the page.
  • Get new comment - to wp_comments table a new line will be added to hold the comment.
  • Upload image - to wp_postmeta table a new line will be added defining the URL of the image.

While the core WordPress plugin and theme files are stored in the WP-Content directory, all plugin and theme settings and content are stored in the WordPress database in new database tables and additional database rows.

So every time you activate new plugins and themes on your WordPress website, the database grows. Unfortunately, the vast majority of plugins and themes do not remove the tables and rows they add to the database when they are deactivated and deleted.

On top of leftover plugin and theme data, WordPress databases can quickly grow in size due to spam comments, redundant post revisions, unused media, and expired temporary options.

The Importance of Backing Up Your WordPress Site

Cleaning up and optimizing your WordPress database shouldn't break your site, however I highly recommend backing up your site before making any changes. This allows you to revert to your standby database if you accidentally delete data you intended to keep.

I recommend that you try BlogVault for daily automatic backups of your website and use the BlogVault backup tool to create one-time backups when needed.
Backup BlogVault

Good WordPress Database Cleanup Techniques

By following good WordPress database cleaning practices, your website database will never get too big.

Recommendation #1: Prevent comment spam

Spam comments and other unwanted comments can greatly increase the size of your WordPress database. You can reduce the impact of comments by disabling backlinks and pingbacks and by using WordPress anti-spam plugins such as Akismet, Antispam Bee, and CleanTalk.

If spam becomes a major problem on your website, you can disable comments entirely.
Akismet Statistics

Recommendation #2: Limit the number of post revisions

The WordPress revision system saves a revision each time you save a draft or publish a post, page, or custom post type. It also automatically saves a copy of your content every 60 seconds. These are known as autosaves or autodrafts.

I have always found the revision system useful as it allows me to compare old draft articles, but it can also be a big waste of resources. While only one autosave is always saved per post or page, WordPress has no limit on the number of revisions that can be saved. This can result in hundreds of article variations being stored in a WordPress table.

A practical way to solve this problem is to limit the number of post revisions that are saved. You can limit WordPress to three post revisions by adding the following line to your wp-config.php file.

define( 'WP_POST_REVISIONS', 3 );

The WordPress revision system can be disabled with the following line.

define( 'WP_POST_REVISIONS', 0 );

In the pursuit of efficiency, some website owners use the above code to completely disable post revisions. This is something that I personally do not recommend giving up, as it leaves you with no backup copies of draft articles. The best option is to limit the number of post versions you keep, and then delete those versions after the content is published.

Recommendation #3: Remove Unwanted WordPress Plugins and Themes

Don't get in the habit of leaving unactivated WordPress plugins and themes on your site. If they are not in use, their files must be deleted and their data must be removed from the WordPress database. This will clean up the WordPress database.

Some plugins and themes have a delete option in the settings area that removes all data, but unfortunately most WordPress products keep all their data. While the rest of the data can be removed from the WordPress database manually, database optimization solutions like WP-Optimize and Plugins Garbage Collector are safer and make the process easier by highlighting all unused tables for you (more on that later).

Recommendation #4: Remove Unused Media

Media files that are not used on your website will still be stored in the WordPress database. This has become a hard-to-avoid problem as WordPress plugins and themes often import media files upon activation but cannot remove them later. This can result in many loose icons, screenshots, unused thumbnails, and other unwanted images.

The WordPress media library shows you which media files are not attached to the content, but it can take a long time to check the media files and check each element for an anchor. Instead, I recommend using the WordPress Media Cleaner plugin, as it will look for unused media files and let you remove them all with one click. In just a few minutes, the plugin found over 1200 unused images from my WordPress media library.
Media cleaner

Recommendation #5: Optimize every database table

If you are comfortable using a database administration tool like phpMyAdmin to edit your WordPress database, you can use the table optimization feature to reduce storage space and improve I/O efficiency. Advanced users can also do this with the MySQL OPTIMIZE TABLE statement.

Don't worry if this is too complicated for you, as the popular WordPress database cleanup plugins allow you to perform this WordPress database optimization with the click of a button.
OPTIMIZE TABLE

Cleaning up the WordPress database with plugins

For most website owners, WordPress database cleanup plugins are the most practical way to clean up the WordPress database.

1. WP-Optimize

WP-Optimize - Clear WordPress Database
WP-Optimize is a comprehensive WordPress optimization solution that offers database cleanup, page caching, image compression, and CSS, HTML, and Javascript minification.

This WordPress database optimization plugin allows you to optimize your database tables and clean up post revisions, auto-saved drafts, broken posts, and metadata. You can also remove spam comments, pingbacks, trackbacks, and expired transients. Optimization can be performed manually or scheduled for daily, weekly, biweekly, or monthly processing.
WP-Optimize Dashboard to clean up WordPress database
One of the most useful tools in WP-Optimize is the database table scanner. It highlights tables that are not being used and shows the number of records and data size for each of them. For each table, a link to the corresponding WordPress plugin is provided, and unnecessary tables can be deleted with the click of a button.
wp-optimize desktop scanner

2. WP Rocket

WP Rocket
WP Rocket is a comprehensive WordPress performance solution that offers page caching, image lazy loading, CSS and Javascript optimization, and database optimization.

On the WordPress database cleanup page, you can remove post revisions, auto drafts, deleted posts, spam comments, deleted comments, and transients. WordPress database tables can also be optimized.
WP Rocket WordPress Database Optimization
WP Rocket's scheduling tool will help you automate your WordPress database optimization. Automatic cleaning can be performed daily, weekly or monthly.
WP Rocket Database Schedule

3 Garbage Collector

Garbage Collector
A plugin I often use to find leftover tables in the WordPress database is called the Plugins Garbage Collector. It works in the same way as WP-Optimize's table scan tool, highlighting tables that are not in use and showing the number of records and data size. Garbage Collector plugins can also check your WordPress table structure and scan hidden database tables.

While currently installed plugins are correctly marked as active by the plugin garbage collector, this plugin struggles to find related WordPress plugins for unused database tables.
Plugins Garbage Collector Cleanup

4.WP Sweep

WP Sweep
WP Sweep is a database optimization solution. It can also clean up posts, auto drafts, spam comments, orphaned data, duplicate meta information, and more. It is also possible to optimize database tables.

On my personal blog, I limit the number of post revisions to three, but WP Sweep showed that I still have a whopping 2179 post revisions. This is 11,15% of the total size of my database.

Compared to other WordPress database optimization plugins, WP Sweep highlights more lost data and duplicate meta information. But since it doesn't have an optimization scheduling feature, you have to do all the cleanup of the database manually. This is not necessarily a bad thing, as it forces you to check every database cleanup.
Cleaning WP Sweep

5. Perfmatters

Perfmatters
Perfmatters is a suite of WordPress security and performance tools. It provides dozens of different tools to reduce page loading times. On its main options page, Perfmatters allows you to limit the number of post revisions or turn them off completely. You can also change the autosave interval from the default minute to two, three, four, or five minutes.

On the main database optimization page, Perfmatters allows you to clean up post revisions, auto drafts, trashed posts, spam comments, trashed comments, and transients. The database can also be optimized, and you can schedule the optimization for a day, a week, or a month. This is a complete set of tools that allows you to effectively optimize and clean up the WordPress database.
Perfmatters database options clear wordpress database

Conclusion

Optimizing the WordPress database is one of the most important maintenance tasks for a WordPress site. By removing unnecessary data from your site's database, you will reduce the size of the database and reduce page load times.

I believe WP-Optimize is the best WordPress database cleaning and optimization solution available to WordPress users today. It can also remove unused data and scan unused tables from remote plugins. Those of you who are already using WordPress productivity solutions like WP Rocket or Perfmatters. May want to consider the WordPress database optimization plugins that are already available for them. In this article, we've covered most of the options to help you clean up your WordPress database quickly.

Reading this article:

Thanks for reading: SEO HELPER | NICOLA.TOP

How useful was this post?

Click on a star to rate it!

Average rating 5 / 5. Vote count: 651

No votes so far! Be the first to rate this post.

Читайте также:

4 Responses

  1. Danielle says:

    Hi there, I enjoy reading through your article. I
    like to write a little comment to support you.

  2. Ross says:

    Нeya i am for the first time here. I came across this board and I find It truly useful & it helped me out much.

    I hope to give something back and aid others ⅼike you aided
    me.

  3. Penny says:

    Your mode of explaining everything in this post is really
    nice, every one be able to simply be aware of it, Thanks a lot.

  4. Collin says:

    What's up i am kavin, its my first time to commenting anywhere, when i
    read this piece of writing i thought i could also make comment due
    to this sensible post.

Добавить комментарий

Your email address will not be published. Обязательные поля помечены *

fifteen − 4 =