Skip to content

Why Is Your Database Slowing Down Your Site? Indexes, Queries and Storage Engines

A database optimization guide: why it bloats and slows your site down, cleaning up revisions, expired transients, spam and orphaned tables, adding indexes, optimizing tables (OPTIMIZE TABLE), object caching with Redis, tuning slow queries, and routine maintenance — with SQL commands and tables.

Performance and speedمنى السالم28 min read
Illustration of a database cylinder with index tabs and a direct query arrow, representing database optimization
On this page

Before anything else, keep this golden rule in mind: don't delete a single row from the database before taking a full, restorable backup. One mistake in a DELETE statement without a correct WHERE clause can wipe out years of content in seconds. The database is not a file to tinker with freely; it is your entire site. For the bigger picture of speeding up your site, see the complete guide to speeding up your website — database optimization is part of a larger system, not a magic standalone fix.

Why does the database slow your site down in the first place?

A WordPress page is not a ready-made file on disk that is served as is; it is built dynamically on every visit. When a page is requested, WordPress runs PHP code that fires a series of SQL queries: Who are you? What are the site settings? What is the menu? Which post was requested? What are its comments? Which plugins are active, and what are their settings? A simple page may fire 20–40 queries, and a heavy WooCommerce store page can exceed 200. Each query needs time to reach the disk, process the result and return it.

This is where the problem shows up: when the database is clean, small and well indexed, these queries finish in milliseconds. But when it bloats — a wp_options table with tens of thousands of rows, a wp_posts table with more revisions than real posts, and a wp_postmeta table swollen with records from deleted plugins — every query becomes slower, the delays add up and TTFB rises. The direct result: content appears later, LCP worsens and the bounce rate goes up.

Optimizing your site's databaseBefore: bloated and slowOld revisionsExpired transientsSpam commentsOrphaned tablesTable overheadSlow queriesActionsClean up the excessIndexesObject cache (Redis)OPTIMIZE TABLEAfter: lean and fastClean databaseFaster queriesLess data + indexes + cache = faster queries and lighter pages
Database optimization: removing the excess (revisions/transients/spam/orphaned tables) + adding indexes + object caching + OPTIMIZE TABLE = faster queries.

The relationship between the database and speed is not simple and linear; it compounds. A query that takes 5 ms on a clean database can take 200 ms on a bloated database without indexes, and if that repeats across 30 queries per page, it is the difference between a site that responds in 300 ms and one that stumbles at 4 seconds. To understand how this fits into the different performance layers, see the types of caching and when to use each.

StageDatabase stateAverage query timeImpact on TTFB
New siteClean, small, indexed1–5 msVery low
After a year of useSome bloat, moderate autoload10–30 msNoticeable
After years + many pluginsBloated, orphaned tables, no indexes50–300 msVery high
Busy WooCommerce store with no maintenanceBloated postmeta, accumulated transients100–500 msCritical

Sources of bloat: where does it come from?

Before you clean, understand what you are cleaning. Database bloat is not magic; it is the result of default behaviors in WordPress and its plugins that pile up silently. The following table summarizes the main sources of bloat and where they live:

SourceTableWhy it accumulatesSeverity
Revisionswp_postsWordPress saves a copy on every edit, with no default limitHigh
Auto-draftswp_postsAutosave every 60 seconds while you writeMedium
Expired transientswp_optionsTemporary data that isn't always deleted after it expiresHigh
Spam and trashed commentswp_commentsThey pile up unless you empty them manuallyMedium
Orphaned tablesSeparate tablesDeleted plugins that didn't clean up their dataMedium
Orphaned postmetawp_postmetaMetadata for deleted posts/revisionsHigh
Pingbacks and trackbackswp_commentsOld link notificationsLow
Overhead (fragmentation)All tablesFreed space not reclaimed after deletionMedium

Revisions and auto-drafts

Every time you click "Update" on a post, WordPress stores the previous version as a "revision" in the wp_posts table. This is a great feature for rolling back, but with no default maximum, a single post can accumulate 50 revisions or more. With hundreds of posts, revisions end up outnumbering the real posts many times over, and all of them are loaded and indexed along with the actual content.

Expired transients

Transients are a caching mechanism inside the database (in wp_options by default). Plugins use them to store the results of expensive operations (such as an external API call) for a set period. The problem is that WordPress doesn't delete an expired transient immediately, only when it is requested; so transients that nobody requests anymore stay in the database forever. On older sites they can make up thousands of rows in wp_options, and the most dangerous are those with autoload = yes.

Orphaned tables and orphaned postmeta

Many plugins create their own tables (wp_redirection_logs, wp_yoast_indexable, etc.). When you delete the plugin from the dashboard, its tables and data are often not deleted, so they remain "orphaned," taking up space and getting included in every backup. Likewise, when posts or revisions are deleted, their metadata rows may remain in wp_postmeta with no parent post — one of the most common silent sources of bloat.

Anatomy of a web app database: where the weight builds up

Before any cleanup, you need a map. Whatever application runs your site, its tables fall into four families, each with a completely different growth pattern — and knowing the family tells you in advance where you will find the bloat:

FamilyWhat it storesGrowth patternBloat risk
Core contentPosts, products, pages, usersGrows at the pace of your businessLow — this is healthy growth
MetadataCustom fields attached to each itemMultiplied: dozens of rows per single itemVery high
Sessions and temporary dataCarts, visitor sessions, cache, temporary tokensGrows with traffic, not with contentHigh, and it explodes suddenly
Logs and queuesEvent logs, scheduled tasks, send attemptsWrites constantly and never deletesThe most dangerous — no ceiling

The last two families are the most dangerous because their growth has nothing to do with the size of your site. A small site with a hundred pages may carry a sessions table with hundreds of thousands of rows because every passing visitor left a trace that was never cleaned up. And the task queue table of a neglected application can pass a million rows within months, so every read from it becomes a full table scan.

Metadata deserves special attention because its structure multiplies by nature: a single content item can drag twenty or thirty rows behind it in a separate table. Worse, deleting the original item doesn't always delete them, so they remain as orphaned rows pointing to something that no longer exists: they take up space, slow down indexes, and are never read.

Always start your diagnosis by sorting tables in descending order of row count and size, not by guessing:

sql
SELECT table_name,
       table_rows,
       ROUND((data_length + index_length) / 1024 / 1024, 2) AS size_mb
FROM information_schema.tables
WHERE table_schema = DATABASE()
ORDER BY (data_length + index_length) DESC
LIMIT 15;

The first table on this list is where you start, whatever your logic tells you.

Scope note: if your site runs on WordPress specifically, the table names and their tools are explained in detail in cleaning up and optimizing the WordPress database — the right place to start.

The query that runs on every request

The most dangerous query in your application is not the slowest one but the one that runs on every request. A query that takes 5 ms and runs once a day doesn't concern you; a query that takes 5 ms and runs ten times on every page load eats half of your response budget.

Most frameworks load a block of "bootstrap" settings at the start of every request, before they even know what they will display. This block is designed to be small, but it bloats silently when plugins store data in it that doesn't belong there: logs, cached results, huge settings arrays. The result is that every visitor — even one reading a static page — pays the price of fetching and unpacking megabytes that are never used.

Three patterns that cost you on every request:

  • Bloated bootstrap loading — the settings block that is always read. The rule of thumb: keep it under one megabyte. Going over three megabytes is a critical condition to fix immediately.
  • The N+1 problem — one query fetches a list, then a separate query runs for each item in it. A page showing 50 products may fire 51 queries instead of two. The fix is in the code, not the database: fetch the whole batch at once.
  • SELECT * on wide rows — it fetches huge text columns that nobody displays. Request only the columns you need.

To measure this honestly, don't rely on your impression: enable the query counter in your development environment and look at the number of queries per page, not their total time. A healthy page stays under 50 queries; anything over 200 calls for an immediate stop. Then review time to first byte to understand where all of this sits in the visitor's experience.

Safe cleanup: backup first

Before running any DELETE or UPDATE statement, take a full backup. This is not a recommendation but a non-negotiable requirement. The backup lets you roll back the moment anything goes wrong. To dig deeper into backup strategy, see the dedicated guide on the subject; the quick command-line version is:

bash
# Full database backup before any cleanup
mysqldump -u DB_USER -p DB_NAME > backup_$(date +%F).sql

# For large files: compress on the fly to save space
mysqldump -u DB_USER -p DB_NAME | gzip > backup_$(date +%F).sql.gz

# Via WP-CLI (reads the connection details from wp-config automatically)
wp db export backup_$(date +%F).sql

And to restore when needed:

bash
# Restore from the backup (careful: replaces the current database)
wp db import backup_2026-06-13.sql

Always test that the backup can actually be restored on a staging environment before you rely on it. A backup whose restore hasn't been tested = no backup.

Manual cleanup with SQL

Once you have a backup, you can clean up with SQL commands directly through phpMyAdmin or the command line. Start with revisions:

sql
-- Delete all revisions
DELETE FROM wp_posts WHERE post_type = 'revision';

-- Delete auto-drafts
DELETE FROM wp_posts WHERE post_status = 'auto-draft';

-- Delete items in the trash
DELETE FROM wp_posts WHERE post_status = 'trash';

Then clean up expired transients. Transients appear in wp_options with names starting with _transient_ and _transient_timeout_ (and the network-wide version _site_transient_):

sql
-- Delete all transients (safe: WordPress rebuilds what it needs)
DELETE FROM wp_options WHERE option_name LIKE '\_transient\_%';
DELETE FROM wp_options WHERE option_name LIKE '\_site\_transient\_%';

Next, clean up spam and trashed comments and pingbacks:

sql
-- Delete spam and trashed comments
DELETE FROM wp_comments WHERE comment_approved = 'spam';
DELETE FROM wp_comments WHERE comment_approved = 'trash';

-- Delete pingbacks and trackbacks
DELETE FROM wp_comments WHERE comment_type IN ('pingback', 'trackback');

Finally, clean up orphaned metadata — one of the most important steps for shrinking wp_postmeta and wp_commentmeta:

sql
-- Delete postmeta for posts that no longer exist (orphaned)
DELETE pm FROM wp_postmeta pm
LEFT JOIN wp_posts p ON p.ID = pm.post_id
WHERE p.ID IS NULL;

-- Delete commentmeta for comments that no longer exist
DELETE cm FROM wp_commentmeta cm
LEFT JOIN wp_comments c ON c.comment_ID = cm.comment_id
WHERE c.comment_ID IS NULL;

-- Delete orphaned term relationships
DELETE tr FROM wp_term_relationships tr
LEFT JOIN wp_posts p ON p.ID = tr.object_id
WHERE p.ID IS NULL;

Cleanup with WP-CLI (faster and safer)

If you have SSH access, WP-CLI is faster and less error-prone than manual SQL, because it works with WordPress logic rather than raw rows. The essential cleanup commands:

bash
# Delete all transients (expired and otherwise)
wp transient delete --all

# Delete expired transients only (more conservative)
wp transient delete --expired

# Run a full database optimization (equivalent to OPTIMIZE TABLE on all tables)
wp db optimize

# Delete revisions via a wp-cli add-on (example with a well-known package)
wp post delete $(wp post list --post_type='revision' --format=ids) --force

The advantage of WP-CLI is that it respects hooks and internal logic, so it doesn't leave orphaned metadata behind the way a direct DELETE on wp_posts alone can.

Cleanup with plugins

If you're not comfortable with SQL or the command line, cleanup plugins offer a relatively safe graphical interface. The table compares the best-known ones:

PluginRevision cleanuptransientsOPTIMIZEAutomatic schedulingNote
WP-OptimizeYesYesYesYesAll-in-one + page caching
Advanced Database CleanerYesYesYesYesGood at detecting orphaned tables
WP-SweepYesYesYesNoUses WordPress functions (safe)
PerfmattersPartialYesNoYesFocuses on reducing autoload

Tip: even with plugins, take a backup before the first cleanup run, and review the report of what will be deleted before confirming. Once the cleanup is done, it is better to deactivate the cleanup plugin rather than leave it active permanently — activate it only for routine maintenance to reduce the load.

Indexes: faster lookups in the database

Imagine a book with no index: to find a word, you have to flip through every page. An index in a database works exactly like a book's index — it lets the database engine jump straight to the rows it needs instead of scanning the whole table (a full table scan). On large tables, the difference between an indexed query and an unindexed one can be the difference between a millisecond and several seconds.

WordPress ships with good default indexes on its core tables. But the problem shows up with queries on wp_postmeta and wp_options when plugins search by unindexed meta_key/meta_value values. Common index types:

Index typeUsed forExample
PRIMARY KEYThe row's unique identifierID in wp_posts
UNIQUEPreventing duplicate valuesUser email
INDEX (regular)Faster search/sortingmeta_key in wp_postmeta
COMPOSITESearching by several columns together(post_id, meta_key)
FULLTEXTFull-text searchPost content

When should you add an index? When you spot a slow query that searches by an unindexed column and runs often. A common example: a plugin that searches wp_postmeta by a specific meta_key on a huge table:

sql
-- Check whether a query uses an index (look for type=ALL = full scan)
EXPLAIN SELECT * FROM wp_postmeta WHERE meta_key = 'my_custom_field';

-- Add an index on meta_key to speed up plugin lookups
ALTER TABLE wp_postmeta ADD INDEX idx_meta_key (meta_key(191));

-- Composite index for queries that combine post_id with meta_key
ALTER TABLE wp_postmeta
ADD INDEX idx_post_meta (post_id, meta_key(191));

An important technical note: we use meta_key(191) (an index on the first 191 characters) because the utf8mb4 encoding limits the length of an index key. Don't overdo indexes: each index speeds up reads but slows down writes and increases size. Add an index only when an actual measurement with EXPLAIN proves it is needed.

OPTIMIZE TABLE and defragmentation

When you delete many rows, the space is not reclaimed automatically; "holes" remain inside the table files, known as overhead or fragmentation. The OPTIMIZE TABLE command rebuilds the table, reclaiming the space, reorganizing the indexes and improving read performance:

sql
-- Check table sizes and overhead (fragmentation) in megabytes
SELECT table_name AS TableName,
       ROUND(data_length/1024/1024, 2) AS Data_MB,
       ROUND(index_length/1024/1024, 2) AS Indexes_MB,
       ROUND(data_free/1024/1024, 2) AS Wasted_MB
FROM information_schema.TABLES
WHERE table_schema = DATABASE()
ORDER BY data_free DESC;

-- Optimize a specific table
OPTIMIZE TABLE wp_postmeta;

-- Optimize several tables at once
OPTIMIZE TABLE wp_posts, wp_postmeta, wp_options, wp_comments;

Important: on InnoDB tables (the modern engine), MySQL internally performs a full rebuild that may lock the table briefly, so run it during low-traffic hours. With WP-CLI, wp db optimize is enough to optimize all tables in one go. There's no need to run OPTIMIZE daily — once a month or after a large deletion is enough.

InnoDB vs. MyISAM storage engines

The storage engine is the mechanism the database uses to store and manage its data. Modern WordPress uses InnoDB by default, but older sites may contain tables stuck on the older MyISAM. The difference is fundamental for performance and reliability:

CriterionInnoDBMyISAM
LockingRow-levelTable-level
TransactionsSupportedNot supported
Crash recoveryExcellent (crash-safe)Weak, prone to corruption
Performance with concurrent writesHighLow (locks the whole table)
Foreign keysSupportedNot supported
Best suited forModern WordPress, storesRead-only archives (rarely)

Row-level locking in InnoDB is the decisive difference: in MyISAM, any write locks the entire table, so the other requests wait; InnoDB locks only the row concerned, allowing concurrent writes — vital for busy sites and stores. To check your tables' engine and convert any old table:

sql
-- Check the storage engine of each table
SELECT table_name, engine
FROM information_schema.TABLES
WHERE table_schema = DATABASE();

-- Convert a table from MyISAM to InnoDB (after a backup)
ALTER TABLE wp_comments ENGINE = InnoDB;

Before converting, make sure your MySQL/MariaDB version supports InnoDB (it has been the default for years), and that the table doesn't rely on MyISAM-specific FULLTEXT indexes that were not supported in very old versions of InnoDB.

Redis object caching to reduce database hits

The most powerful performance upgrade after cleanup is a persistent object cache. By default, WordPress keeps query results in memory for the duration of a single request only; as soon as the page finishes loading, they are forgotten. The next request repeats the same queries from scratch. A persistent object cache (via Redis or Memcached) keeps these results in fast memory across requests, so you don't hit the database over and over with the same question.

Cache layers: where is the request caught?BrowserBrowserEdge / CDNEdgePage cachePageObject cacheObjectDatabaseOriginA hit at any layer = instant response, no full trip
Cache layers in order: the earlier the layer where the request is served (far right), the faster the response comes back without reaching the database.

The difference is huge in the admin dashboard, in stores and on dynamic pages that don't benefit from full-page caching. To understand how object caching fits among the different cache layers (browser, page, object, opcode), see the types of caching and when to use each. Redis is usually enabled with a plugin such as Redis Object Cache after installing a Redis server, then configured in wp-config.php:

php
// In wp-config.php — Redis connection settings
define( 'WP_REDIS_HOST', '127.0.0.1' );
define( 'WP_REDIS_PORT', 6379 );
define( 'WP_REDIS_DATABASE', 0 );

// Connection timeout (seconds) to avoid hanging if Redis goes down
define( 'WP_REDIS_TIMEOUT', 1 );
define( 'WP_REDIS_READ_TIMEOUT', 1 );

// Unique key prefix (useful when several sites share one Redis)
define( 'WP_CACHE_KEY_SALT', 'mysite_' );
LayerStoresReduces database hits?Best suited for
Page cacheFull HTMLYes (for visitors)Static content
Object cache (Redis)Query resultsYes (dashboard + dynamic)Stores and busy sites
Opcode cache (OPcache)Compiled PHP codeNo (speeds up PHP)All sites

Note: Redis requires a server that supports it (a VPS or managed hosting that provides it). Many cheap shared hosting plans don't offer Redis, which is one of the reasons to choose serious hosting for busy sites.

Tracking and tuning slow queries

Don't optimize what you don't measure. Before you add an index or rewrite a query, you need to know which queries are actually slow. Two main tools: the slow query log at the MySQL level, and the Query Monitor plugin at the WordPress level.

Enabling the slow query log

The slow query log records every query that exceeds a time you set. You can enable it temporarily without restarting the server:

sql
-- Enable the slow query log (temporary, until restart)
SET GLOBAL slow_query_log = 'ON';

-- Log any query that takes longer than two seconds
SET GLOBAL long_query_time = 2;

-- Log file path
SET GLOBAL slow_query_log_file = '/var/log/mysql/slow.log';

-- Log queries that don't use an index (useful for diagnosis)
SET GLOBAL log_queries_not_using_indexes = 'ON';

To enable it permanently, add the following to the MySQL configuration file (my.cnf or mysqld.cnf):

bash
# In the [mysqld] section of my.cnf
slow_query_log = 1
slow_query_log_file = /var/log/mysql/slow.log
long_query_time = 2
log_queries_not_using_indexes = 1

Then use a tool such as mysqldumpslow to summarize the slowest and most frequent queries:

bash
# Summarize the 10 slowest queries by average time
mysqldumpslow -s at -t 10 /var/log/mysql/slow.log

Query Monitor inside WordPress

The free Query Monitor plugin shows — for every page you visit while logged in as an administrator — all queries, their timing, the plugin responsible for each, and duplicate queries. It is the fastest way to link a slow query to its source: you may discover that a single plugin is responsible for half of the database time, so you replace or deactivate it.

ToolLevelRevealsBest suited for
Slow Query LogMySQLSlow queries across the whole siteServer diagnostics
Query MonitorWordPressPage queries + their sourceLinking a query to a plugin
EXPLAINSQLExecution plan of a single queryConfirming index usage
New Relic / APMServerPerformance over timeLarge sites

Cut bloat at the application, not the database

Cleanup is a treatment you repeat every month; prevention is a setting you configure once. The difference is that a database never deletes anything on its own — every row written stays until someone deletes it explicitly. So any data your application writes without a defined retention policy will grow with no ceiling, and the question is when it becomes a problem, not whether.

Four policies that settle most unhealthy growth:

Data typeThe right policyThe common mistake
Content versions and draftsKeep a limited number per item"Keep everything to be safe"
Sessions and abandoned cartsDelete anything older than 30–60 daysNo policy at all
Temporary data and stored cacheDelete expired entries periodicallyAssuming the application will clean up
Logs and event logsKeep a time window, then rotateKeeping everything since day one

The key is to make deletion a scheduled task that runs on its own, not something you have to remember. A weekly task that deletes expired sessions and old logs keeps the database at a stable size indefinitely — see the cron jobs guide to set it up correctly on the server.

And mind an important order: apply the retention policy before you delete the backlog. If you clean up a million rows today without a policy, you will find them back within months. If you set the policy first, the big cleanup becomes a one-time operation rather than an endless cycle.

Routine maintenance: a practical schedule

Database optimization is not a one-time event but a habit. The following table suggests a realistic routine by site type:

TaskBlog/brochure siteBusy WooCommerce store
Full backupDailyEvery 6 hours or daily
Delete revisions and draftsMonthlyWeekly
Delete expired transientsMonthlyWeekly
Empty comment spamWeeklyWeekly
OPTIMIZE TABLE / wp db optimizeMonthlyMonthly
Check autoload sizeEvery 3 monthsMonthly
Review orphaned tablesAfter every plugin removalAfter every plugin removal
Review the slow query logWhen you notice slownessMonthly

Most of these tasks can be automated with a scheduling plugin (WP-Optimize supports scheduling) or with a cron job on the server that calls WP-CLI commands automatically. Automation ensures continuity instead of relying on manual memory.

Common mistakes to avoid

Many sites are harmed more by a misguided "optimization" than by neglect. Avoid these mistakes:

MistakeWhy it's dangerousThe right way
Deleting without a backupOne mistake = permanent lossA full, tested backup first
DELETE without a precise WHEREWipes out more than you intendedReview the statement, test it on staging
Disabling revisions completelyYou lose the ability to roll backLimit them to 3–5, not zero
Overdoing indexesSlows down writes and inflates sizeIndex only after measuring with EXPLAIN
Dropping a table without checkingIt may actually be in useVerify that it really is orphaned
Leaving a cleanup plugin active permanentlyA constant load on the siteActivate it for maintenance only
OPTIMIZE at peak timeMay lock tables brieflyRun it during low-traffic hours

Expert tips for a healthy database

  • Keep staging separate from production: test every cleanup or engine conversion on a staging copy first, especially ALTER TABLE conversions on huge tables.
  • Watch plugins at install time: some plugins store massive data with autoload = yes. Check autoload after installing any heavy new plugin.
  • Clean up when removing plugins: before deleting any plugin, check whether it offers a "delete data on uninstall" option; otherwise it will leave orphaned tables and rows behind.
  • Use WP-CLI for automation: commands such as wp transient delete --expired and wp db optimize are ideal for periodic, hands-off cron jobs.
  • Don't mix causes: change one thing and measure its effect before moving on to the next; applying ten changes at once hides what helped and what hurt.
  • The database is part of a system: a clean database doesn't help on its own if the hosting is slow or caching is disabled. Read speeding up a WordPress site and understanding Core Web Vitals to see the full picture.

Database optimization is not an isolated technical task but a direct investment in your site's speed, your visitors' experience and your search rankings. Start with a backup, then clean up the bloat, add the indexes you need, enable object caching and track slow queries — and turn maintenance into a routine habit rather than an emergency campaign. And choose hosting that gives you the tools all of this requires: SSH, Redis and sufficient resources.

Frequently asked questions

Does database optimization actually speed up my site? Yes, but only to the extent that the database contributes to your slowness. If TTFB is high because of slow queries, a bloated autoload and oversized tables, then cleanup, indexing and object caching make a clear difference. But if the slowness comes from uncompressed images or heavy JavaScript, the database is not the bottleneck. So measure first where the time is being lost.

How often should I clean up the database? For blogs and brochure sites, a full cleanup once a month is usually enough. For busy stores and content-heavy sites: weekly for revisions and transients, monthly for OPTIMIZE. It is best to automate these tasks with a scheduler or cron instead of relying on memory.

Is deleting revisions safe? Yes. Deleting revisions does not affect published content; a revision is just a saved earlier version for rolling back. But take a backup first as standard practice, and consider keeping the last 3–5 revisions of each post instead of deleting them all, using the WP_POST_REVISIONS constant.

What is the difference between OPTIMIZE TABLE and cleaning up rows? Cleaning up rows (deleting revisions and transients) reduces the amount of data. OPTIMIZE TABLE, on the other hand, rebuilds the table to reclaim the wasted space (overhead) left behind by deletions and reorganizes the indexes. The correct order: clean up the rows first, then run OPTIMIZE to reclaim the space.

Do I really need Redis for my site? It depends on the type of site. A static blog with good page caching may not need it much. But stores, membership sites and forums — where content is dynamic and full-page caching doesn't help — benefit greatly from Redis object caching, which reduces hits on the database. Redis requires hosting that supports it (a VPS or managed hosting).

What is autoload and why does it matter? autoload is a column in the wp_options table that determines whether an option is loaded into memory on every page load. All settings with autoload = yes are fetched on every visit. If a plugin stores large data with autoload = yes, alloptions bloats and TTFB rises. A healthy total autoload size stays below one megabyte.

Can I optimize on shared hosting without SSH? Yes. You can clean up through phpMyAdmin (from the cPanel control panel) with SQL commands, or with plugins such as WP-Optimize from the WordPress dashboard. But features such as a server-level slow query log and Redis usually require a VPS or managed hosting that provides these capabilities.

What should I do with orphaned tables from plugins I deleted? First, make absolutely sure the table really is orphaned (it belongs to a deleted plugin and no current plugin uses it). Tools such as Advanced Database Cleaner detect them and help you delete them safely. Take a backup, then drop the table with DROP TABLE once you are sure. Don't rush — some tables are shared between plugins.

Are optimization plugins enough, or do I need manual SQL? For most users, a trusted plugin such as WP-Optimize or Advanced Database Cleaner covers 90% of the need safely, through a graphical interface. Manual SQL and WP-CLI give finer control and suit professionals and special cases (a custom index, a specific query). Most important in both cases: a backup before any deletion.

Can optimization break my site? If you follow the rules, the risk is small: a backup first, delete only what you are sure about, and test major conversions on staging. The risks come from guesswork: a DELETE without a precise WHERE, deleting core WordPress options, or deleting a table that is in use. Stick to the safe cleanup described here and you will be fine.

Sources

Frequently asked questions

Does database optimization actually speed up my site?

Yes, but only to the extent that the database contributes to your slowness. If TTFB is high because of slow queries, a bloated autoload and oversized tables, then cleanup, indexing and object caching make a clear difference. But if the slowness comes from uncompressed images or heavy JavaScript, the database is not the bottleneck. So measure first where the time is being lost.

How often should I clean up the database?

For blogs and brochure sites, a full cleanup once a month is usually enough. For busy stores and content-heavy sites: weekly for revisions and transients, monthly for OPTIMIZE. It is best to automate these tasks with a scheduler or cron instead of relying on memory.

Is deleting revisions safe?

Yes. Deleting revisions does not affect published content; a revision is just a saved earlier version for rolling back. But take a backup first as standard practice, and consider keeping the last 3–5 revisions of each post instead of deleting them all, using the WP_POST_REVISIONS constant.

What is the difference between OPTIMIZE TABLE and cleaning up rows?

Cleaning up rows (deleting revisions and transients) reduces the amount of data. OPTIMIZE TABLE, on the other hand, rebuilds the table to reclaim the wasted space (overhead) left behind by deletions and reorganizes the indexes. The correct order: clean up the rows first, then run OPTIMIZE to reclaim the space.

Do I really need Redis for my site?

It depends on the type of site. A static blog with good page caching may not need it much. But stores, membership sites and forums — where content is dynamic and full-page caching doesn't help — benefit greatly from Redis object caching, which reduces hits on the database. Redis requires hosting that supports it (a VPS or managed hosting).

What is autoload and why does it matter?

autoload is a column in the wp_options table that determines whether an option is loaded into memory on every page load. All settings with autoload = yes are fetched on every visit. If a plugin stores large data with autoload = yes, alloptions bloats and TTFB rises. A healthy total autoload size stays below one megabyte.

Can I optimize on shared hosting without SSH?

Yes. You can clean up through phpMyAdmin (from the cPanel control panel) with SQL commands, or with plugins such as WP-Optimize from the WordPress dashboard. But features such as a server-level slow query log and Redis usually require a VPS or managed hosting that provides these capabilities.

What should I do with orphaned tables from plugins I deleted?

First, make absolutely sure the table really is orphaned (it belongs to a deleted plugin and no current plugin uses it). Tools such as Advanced Database Cleaner detect them and help you delete them safely. Take a backup, then drop the table with DROP TABLE once you are sure. Don't rush — some tables are shared between plugins.

Are optimization plugins enough, or do I need manual SQL?

For most users, a trusted plugin such as WP-Optimize or Advanced Database Cleaner covers 90% of the need safely, through a graphical interface. Manual SQL and WP-CLI give finer control and suit professionals and special cases (a custom index, a specific query). Most important in both cases: a backup before any deletion.

Can optimization break my site?

If you follow the rules, the risk is small: a backup first, delete only what you are sure about, and test major conversions on staging. The risks come from guesswork: a DELETE without a precise WHERE, deleting core WordPress options, or deleting a table that is in use. Stick to the safe cleanup described here and you will be fine.