How to perform a Wordpress database cleanup

pattern 21

🚀Boost your website Speed & Performance

*No spams

Much like your front end, you should also strive to optimize your back end. Cleaning and optimizing your database is a good practice.

To help on optimizing a Wordpress database, here are 4 ways to clean it. If you already have a cache or speed optimization plugin running, you can clean using Wp CLI, Advanced Database Cleaner, or optimize with PhPMyAdmin.

⚠️ Be careful when cleaning your database. Consider backup your database before any changes.

Clean database using Wp Rocket plugin

Wp Rocket provides a simple interface for deleting unused database pieces such as post revisions, auto-draft wordpress posts/pages, trashed posts, comments, and plugin transients.

wp rocket database cleanup
Wp Rocket database full database cleanup options

Clean database using Wp Optimize plugin

Wp Optimize is a free plugin offering database cleanup, with more advanced and extra options.

optimize database wp optimize
Wp Optimize Wordpress database cleanup options

Wp Optimize also can schedule database cleanups:

optimize database wp optimize 3
Wp Optimize Wordpress database cleanup general options

List of tables and plugins that may be related to that table, helping you choose if it’s a used table:

optimize database wp optimize 2
List of tables and plugins that probably uses that table

Clean database without a plugin with Wp Cli

Wp Cli is a free command line Wordpress utility tool. To install Wp CLI follow this guide.

Wp Cli might be available on your Wordpress install. Check for the hosting companies with WP CLI installed. If you’re using a Wordpress Bitnami version, WP CLI is already available. 

The commands for optimizing the database are:

Delete all spam comments(Marked as spam).

$ wp comment delete $(wp comment list --status=spam --format=ids)

Delete all comments marked as a hold.

$ wp comment delete $(wp comment list --status=hold --format=ids)

Delete Expired Transients(Temporary plugin data), safe to exclude assuming it's not needed.

$ wp transient delete --expired

Optimizes the database

wp db optimize

Delete all posts in the trash

$ wp post delete $(wp post list --post_status=trash --format=ids)

Clean database with Advanced Database Cleaner plugin

Advanced Database Cleaner plugin offers all majors options to clean up the database, including orphaned items:

optimize database advanced db cleaner
Advanced DB cleanup plugin main options

List of scanned tables(Pro version shows plugins belonging to each table):

optimize database advanced db cleaner 2

Optimize database with PHPMyAdmin

To optimize the Wordpress database with PHPMyAdmin, log into your PHPMyAdmin, go to your databases, click on one database, check all the tables of the DB you want to optimize, then click on the bottom “Optimize table”. It will optimize all the tables selected.

optimize db php my admin

Get your WordPress Core Web Vitals optimized and your pages faster!

guest

0 Comments
Oldest
Newest Most Voted
Inline Feedbacks
View all comments