Skip to content

How to Optimize a Large WordPress Database Safely

Find the actual size of WordPress tables, clearable data, and slow queries, and optimize the database without removing the necessary order or settings.

Author Bipida Editorial Team Published
Share this article

Growing a database alone does not prove that WordPress is slow. A store with real orders may have a multi-gigabyte database and healthy performance, while a small site fails due to improper autoload, an indexless query, or a row. The goal of optimization is not to reduce volume at any cost; it must correct the cost of reading and writing, proprietary data, and the possibility of recovery.

Quick answer:First, get a recoverable backup, measure the size of the table and index separately, see the growth over time, and attribute the larger table to the add-on or proprietary capability. Then check the retention and official deletion tools for the same component. First, measure the deleted or modified index operation on the clone of both the run and the time, lock, and the result of the operation.

When is the size of the database really the problem?

  • Backup or restore passes through the RTO acceptable.
  • Orange queries read lots of rows or spill over onto the disk.
  • The table grows continuously without a maintenance cycle.
  • The wp-admin, search, checkout or job background is waiting for the database.
  • There is not enough space for temporary table, log or maintenance.
  • Data belonging to the plugin is deleted or job failed.

Interpret size along with latency, growth rate, and workload. Running a quick query on a large table may be healthier than scanning a full table on a small table.

Before any cleanup: make a way back.

A new dump is not enough unless it is complete and the ability to restore is confirmed. For a store site, the gap between backup and change time can include new order and payment, so a maintenance window or delta retention plan is required. Measure the restore time on a separate environment and do not replace the previous backup with a new output to keep a standalone recovery point.

Make a database map of the data.

In MySQL/MariaDB, you can approximate the size of data and index frominformation_schema.tablesTake the database name from a valid configuration and don't put the password in the command history or public report:

SELECT table_name,
       ROUND(data_length / 1024 / 1024, 1) AS data_mb,
       ROUND(index_length / 1024 / 1024, 1) AS index_mb,
       table_rows
FROM information_schema.tables
WHERE table_schema = DATABASE()
ORDER BY data_length + index_length DESC;

table_rowsFor some engines, it is a projection. This report only reviews the candidate and does not allow table deletion.wp_It's not.

What does the big table belong to?

The model.The main questionA low-risk measure.
posts/postmetaWhich plugin is revision, product, or meta?Reporting the type of record and ownership data
optionsWhat do autoload and transient have to do with each other?Analyze the option name and size, not the group elimination
Session / row / logIs retention and consumer healthy?Official cleanup tool and cause of backlog
Old add-on tablesIs the plugin really deleted and data not stored?Uninstall and independent backup documents
WooCommerceIs it order data, lookup or action scheduler?Your own tools for commerce and report testing

A practical and reversible process.

  1. Baseline the volume, latency and growth rate.
  2. Take the backup file and database and test the restore.
  3. List the major tables and their indexes.
  4. Specify the owner of each table or prefix and retention policy.
  5. Check the data sample and the oldest/newest timestamp.
  6. Record the official clearance on the clone run and the difference in the number of records.
  7. Batch the operation to control transaction and lock.
  8. Once you've run it, re-measure your business paths and target queries.

Revision, transient and orphan; label is not enough.

Revisions may be necessary to return the editing content. The expired transient is usually a clearing candidate, but has a separate active transient or timeout. orphan should also be defined based on actual relationship and incremental behavior; a parentless meta may be a defective migration effect. The clearing tool should not simply decide by matching the table name.

When is the Optimization Table useful?

This is not a slow general treatment operation. The behavior of reclaim and rebuild depends on the engine and version, and may result in significant I/O, temporary space, and lock. First, check fragmentation, required space, runtime, and the possibility of an online operation for an accurate version.

Should we add the index or not?

Decide only after you have seen the actual query and execution plan. The appropriate index can reduce the rows examined, but the additional index increases the disk space and the cost of insert/update.Finding the slow WordPress queries.A better starting point is the index of bias.

Check the wp_options separately

In this size of the autoload table, the number of options and the owner of each record is more important than the total volume. Removing an unknown option can ruin critical settings, license, route, or cache.The growth guide to the wp_options tableLook at that.

What should we test after cleaning?

  • Entry and storage of written or product
  • Search and filter radiation.
  • The check-out, the check-out, the payment and the callback.
  • Cron, queue, email and external sync
  • Old reports and orders page.
  • Backup and restore time trial

Reducing volume without improving the target query or maintenance operation is not a functional result.

Common Mistakes

  • Delete all transients or tables on production without backup
  • Use of fixed prefixwp_In the orders.
  • Emptying the queue to hide the spoiled consumer.
  • Restore the old store backup and lose the new order.
  • Create an index based on guesses or recommendations related to another version
  • The implementation of the public optimization at peak times

How can we prevent it from growing again?

Specify the retention policy for log, session, revision and queue; monitor failure and oldest job; record weekly growth rates of the table and check the data model and uninstall before installing the plugin.

When is a specialist examination necessary?

If the trading table is too large, you don't have free space to rebuild or Query is slowly involved with checkout and ordering, direct testing is risky.WordPress speed boost serviceYou can analyze the size, slow log and execution plan on the clone and make rollback changes.

Common Questions

Is the database clearing plugin enough?

Only when the data type identifies the owner and retention correctly. Check the precise preview, backup and copy behavior before running.

Does deleting revisions speed up the site?

No, not necessarily. It depends on the volume and the queries, and the editing history is lost.

Is a few gigabytes of data a problem?

No. Latency, plan, growth rate and recovery time are more functional metrics than volume alone.

How wp-cron Can Cause High CPU Usage and Slow Down WordPress
Find wp-cron events, backlog jobs, and execute co-folders, and reduce CPU and WordPress latency without blinding the queue.