Please I just migrated my site and I found out that wp_postmeta consumes most of my cpu resources, Is the any Sql code to Delete all post meta except the featured image. I dont want to Use wp functions for this. Just need only phpmyadmin sql code. I have read this similar Post, But I need the sql code for it, not functions
I rewrote the function from the link in your question to SQL.
Keep in mind that this script will also clear the page-templates assigned to the pages.
Make a backup of the
wp_postmeta table first.
DELETE pm FROM wp_postmeta pm LEFT JOIN wp_posts p ON pm.post_id = p.id WHERE (p.post_type IN ('post', 'page') AND pm.meta_key <> '_thumbnail_id') OR (p.post_type = 'attachment' AND pm.meta_key <> '_wp_attached_file' AND pm.meta_key <> '_wp_attachment_metadata')