Much the same as your front end, you should also strive to optimize your backend. 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.
Consider buying Wp Rocket with our reflink.
Clean database using Wp Optimize plugin
Wp Optimize is a free plugin that also offers database cleanup, with more advanced and extra options.
Wp Optimize also can schedule database cleanups:
List of tables and plugins that may be related to that table, helping you choose if it’s a used 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.
For the full hosting companies with WP CLI installed, check here. 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 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:
List of scanned tables(Pro version shows plugins belonging to each table):
Optimize database with PhpMyadmin
To optimize the WordPress database with PHPMyAdmin, log into your PHPMyAdmin, go to your databases, click on one database, and 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.
Get your Core Web Vitals optimized