Over time, as posts are updated, created, or deleted, the wp_postmeta table can become large and inhibit your website performance. In this article, we are going to show you how to clean up old, unnecessary post metadata from the wp_postmeta table to help your WordPress site run more efficiently.
- Before continuing, make a backup of your database. This step is critical as we are making mass deletions that can potentially break things on your site.
- Log into cPanel.
Next, scroll down to the Databases section and click on phpMyAdmin.
Within PHPMyAdmin, select your WordPress database on the left side column. If you are unsure of the database that your WordPress site is using, follow our guide on finding your WordPress database name.
At the top of the page, click on SQL.
Inside the text area, enter the following:
SELECT * FROM wp_postmeta pm LEFT JOIN wp_posts wp ON wp.ID = pm.post_id WHERE wp.ID IS NULL;
DELETE pm FROM wp_postmeta pm LEFT JOIN wp_posts wp ON wp.ID = pm.post_id WHERE wp.ID IS NULL;
- Then, press the Go button on the bottom right.
PHPMyAdmin will either let you know how many items it removed or state that the result is empty which means that nothing was found. Congratulations! Your wp_postmeta table has now been cleaned up.