WordPress Database and cleaning out old data

WordPress / WooCommerce Database is huge.  I'm helping with a store that over the years the database tables have become huge.  Literally millions of table entries.  Is there any way to get rid of data that is no longer needed in the postmeta table?  Is there old information that no longer needs to be stored?

I was told I can use the following in MyPHPadmin:
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;

Open in new window


But if I do that, will I loos anything from my WooCommerce Store?
LVL 8
rgranlundAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

David Johnson, CD, MVPRetiredCommented:
Is your site broken? If not why are you trying to fix something that is not broken. Unless you are absolutely 100% sure then don't change things just because you think something is wrong.
I wouldn't worry about the woocommerce database but for the Wordpress database there are several optimizations https://www.shoutmeloud.com/reduce-wordpress-database-size.html
David FavorLinux/LXD/WordPress/Hosting SavantCommented:
As David suggested, if it ain't broke, don't fix it.

Woo tends to only generate data Woo requires.

Before you delete any data, best only do it through Woo, rather than raw database commands or run your approach by Woo support via a support ticket.

In general, if you muck about with Woo data (which is complex), you can end up with all manner of orphan data in your database.

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Databases

From novice to tech pro — start learning today.