• Skip to main content
  • Skip to primary sidebar
  • Home
  • WordPress
  • web Hosting
  • linux
  • mysql
  • nginx
  • apache2
  • devops

Raju Ginni

wordpress tutorials seo hosting etc

Wp_postmeta too large Clean up what is it & why

July 20, 2025 By Raju Ginne

The wp_postmeta table in WordPress stores metadata or additional information about posts, pages, and custom post types. Over time, this table can become excessively large (“too large”) due to several reasons, which can lead to slower website performance and increased database size.

 

wp_postmeta is a core WordPress table that stores “extra” information about every post, page, attachment, custom post type, etc. Each row is a simple key-value pair:

  • meta_id – internal row ID
  • post_id – which post this belongs to
  • meta_key – the name of the piece of data
  • meta_value – the actual data (can be up to 4 GB long in TEXT)

Table of Contents

Toggle
  • Why it can explode in size
  • Quick diagnosis
  • Safe cleanup checklist
  • Preventing future bloat

Why it can explode in size

  1. Plugins/themes write a lot of autogenerated keys (especially page-builder, SEO, WooCommerce, ACF, LMS, multilingual, analytics plugins).
    • Example: _elementor_css, _yoast_wpseo_*, _wc_session_*, _wp_attachment_backup_sizes …
  2. Revisions – every revision duplicates most meta keys.
  3. Orphaned data – when you delete a post the meta is often left behind.
  4. Autoloaded options – some plugins incorrectly store transient/session data as post meta instead of using the options table.
  5. Long JSON blobs – page builders store full layouts or Base64-encoded images in meta_value.

Quick diagnosis

sql

-- How big is it?
SELECT
  ROUND(SUM(LENGTH(meta_value))/1024/1024, 2) AS GB
FROM wp_postmeta;

-- Top 20 largest keys
SELECT meta_key,
       COUNT(*)        AS rows,
       ROUND(SUM(LENGTH(meta_value))/1024/1024, 2) AS MB
FROM   wp_postmeta
GROUP  BY meta_key
ORDER  BY MB DESC
LIMIT 20;

Look for keys that are huge but not obviously useful to you.

Safe cleanup checklist

  1. Back up the database
    mysqldump -uUSER -p DBNAME > pre-cleanup.sql
  2. Delete orphaned postmeta
    sql

    DELETE pm
    FROM wp_postmeta pm
    LEFT JOIN wp_posts p ON pm.post_id = p.ID
    WHERE p.ID IS NULL;
  3. Delete old revisions and their meta
    (Use WP-CLI; cleans both wp_posts and wp_postmeta)

    bash

    wp post delete $(wp post list --post_type='revision' --posts_per_page=-1 --format=ids) --force
  4. Drop known bloat keys you no longer need
    Example:

    sql
    DELETE FROM wp_postmeta
    WHERE meta_key IN ('_edit_last', '_edit_lock', '_wp_old_slug', '_wp_trash_meta_time');
  5. Shrink oversized keys
    If _elementor_css or _fl_builder_* rows are tens of megabytes each, consider regenerating them later and removing the old ones:

    sql

    DELETE FROM wp_postmeta WHERE meta_key = '_elementor_css';
  6. Run OPTIMIZE TABLE
    After large deletions, reclaim space:

    sql

    OPTIMIZE TABLE wp_postmeta;

Preventing future bloat

  • Disable or limit post revisions in wp-config.php:
    define('WP_POST_REVISIONS', 3);
  • Use object cache so plugins stop storing transients as post meta.
  • Periodically run wp-cli cleanup commands in cron.
  • Review new plugins for how much meta they create.

If the table is still massive after cleanup, you can also convert meta_value from LONGTEXT to MEDIUMTEXT (if you are sure no value exceeds 16 MB) to shave a byte per row, but that’s rarely worth the risk.

Always test on a staging site first.

 

WordPress database optimization (don’t neglect) plugins & phpmyadmin manually

About Raju Ginne

AMFI Registered mutual fund distributor based in Hyderabad. you may contact me for mutual funds SIP investments Whatsapp: 9966367675.
nism certified research analyst

Primary Sidebar

hi i am raju ginni, primalry i manage wordpress websites on GCP cloud platform as a cloud engineer, and create content on passionate things.
you can follow me on youtbe

© 2025 - All Rights Reserved Disclaimer & Privacy Policy