How to empty your Wordpress wp_postmeta table

Procédure

How to empty the wp_postmeta table if it is a large size

If you've been using WordPress for a while, it's likely that your wp_postmeta table is a significant size.
This article will explain how to clear the wp_postmeta table in order to reduce the size of your WordPress database.

How to empty the wp_postmeta table if it is large:

To reduce the size of the wp_postmeta table, you will need to execute MySQL queries. To execute these queries, you need to connect to PhpMyAdmin, then click on the SQL tab, paste the desired query into the field and press the Execute button.

  • To delete revisions:
DELETE FROM `wp_posts` WHERE `post_type`="revision"

  • To delete deleted items (in the recycle bin):
DELETE FROM `wp_posts` WHERE `post_status`="trash"

  • To delete orphaned posts:
DELETE m FROM `wp_postmeta` AS m LEFT JOIN `wp_posts` AS p ON m.`post_id` = p.`ID` WHERE p.`ID` IS NULL

  • To obtain the full list of meta-keys:
 SELECT DISTINCT meta_key FROM `wp_postmeta` SELECT DISTINCT meta_key FROM `wp_postmeta` 

The query above is not a table cleanup query.
You can use it to obtain a list of meta-keys in order to remove unused data from your database.

The following queries explain how to delete this data.

  • To remove meta keys from plugins:
DELETE FROM `wp_postmeta` WHERE `meta_key` LIKE '%PLUGIN_NAME%'.

to replace PLUGIN_NAME by one of the values obtained in the previous request.

Once you have used these queries to clean up the wp_postmeta table you can calculate the new size of the table using the query below:

SELECT (SUM(DATA_LENGTH + INDEX_LENGTH))/1048567 FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_NAME = 'wp_postmeta';

Conclusion:

You can now clean up the wp_postmeta table to reduce the size of your Mysql database.
This will allow you to remove unnecessary data from your database and thus reduce its size.
Don't hesitate to contact our technical department via an incident ticket if you have any questions.

Rate this article :

5/5 | 3 opinion

This article was useful to you ?

Article utileYes

Article non utileNo

Vous souhaitez nous laisser un commentaire concernant cet article ?

Si cela concerne une erreur dans la documentation ou un manque d'informations, n'hésitez pas à nous en faire part depuis le formulaire.

Pour toute question non liée à cette documentation ou problème technique sur l'un de vos services, contactez le support commercial ou le support technique

MerciMerci ! N'hésitez pas à poser des questions sur nos documentations si vous souhaitez plus d'informations et nous aider à les améliorer.


Vous avez noté 0 étoile(s)

Similar articles

1mn reading

How does Yoast SEO work?

4mn reading

How can you optimise your Wordpress site?

1mn reading

How do I use Gutenberg on Wordpress?

2mn reading

How do I disable the Gutenberg editor on Wordpress?


Ask the LWS team and its community a question