Someone opens phpMyAdmin looking for a slow query and finds that the largest table in the database is wp_woocommerce_sessions, sitting at two, three, sometimes four gigabytes. The usual next move is to empty it. That move loses live customer carts.
A sessions table that size is almost never a sign that you are busy. It is a sign that the cleanup job stopped running, and possibly that a structural problem is making the cleanup itself fail. This guide covers how to tell those apart, how to clear it safely, and the missing index that causes the whole problem to repeat.
What the sessions table actually holds
WooCommerce stores cart contents and session state for every visitor in wp_woocommerce_sessions, keyed by a hash in a cookie. A visitor browsing your store with nothing in their cart still gets a row. Each row carries an expiry timestamp, and a scheduled cleanup removes rows past their expiry.
This is live state, not a log. That distinction decides everything about how you treat it. A log records what already happened and can be emptied safely. Live state is what somebody is doing right now, and the only rows you may delete are the expired ones.
Why it grew
There are three realistic causes and they need different fixes.
The cleanup event stopped running
This is the common one. The cleanup runs on WordPress scheduled tasks. If WP-Cron has been disabled without a real server cron replacing it, or the Action Scheduler queue is jammed, the cleanup simply never fires and expired rows accumulate forever.
Bot traffic is creating sessions faster than they expire
Every add-to-cart request from a new client creates a session row, and crawlers walking product and filter URLs generate these in volume. If your table is growing quickly and your sales are not, this is usually why.
The table is genuinely busy
Occasionally the size is legitimate for the traffic. This is the case where emptying it would do real damage, and the reason to check expired row count before deleting anything.
Measure before you touch anything
Two numbers tell you which problem you have. First, the table size:
SELECT table_name,
ROUND(((data_length + index_length) / 1024 / 1024), 2) AS mb
FROM information_schema.TABLES
WHERE table_schema = DATABASE()
AND table_name = 'wp_woocommerce_sessions';
Then the ratio that actually matters, expired rows against total rows:
SELECT COUNT(*) AS total,
SUM(session_expiry < UNIX_TIMESTAMP()) AS expired
FROM wp_woocommerce_sessions;
If almost everything is expired, your cleanup has stopped and the fix below applies. If very little is expired, the table is doing its job and the size reflects real traffic, so leave the rows alone and look at your hosting resources instead.
Why a big sessions table slows the whole store down
The obvious cost is disk, and that is the least important part. The real damage is to the InnoDB buffer pool, which is the memory MySQL uses to keep frequently read data close at hand. When the sessions table bloats, its pages crowd out the product and order pages that your storefront actually needs on every request. Queries that have nothing to do with sessions get slower, which is why this problem usually presents as a general slowdown rather than a checkout problem.
The missing index nobody mentions
Here is the part that makes this recur. The table ships with indexes on session_id and session_key only. The cleanup deletes on session_expiry, which is not indexed. On a small table nobody notices. On a table with tens of thousands of rows, that DELETE becomes a full table scan.
Meanwhile every active shopper is writing to the same table, because adding to a cart performs an insert or update on the session row. A long scanning DELETE holding locks against a stream of concurrent writes is a recipe for lock contention and, on busy stores, deadlocks during the cleanup run. The cleanup then fails, which leaves more expired rows, which makes the next scan slower.
Adding the index breaks the cycle:
ALTER TABLE wp_woocommerce_sessions
ADD INDEX idx_session_expiry (session_expiry);

Clearing it safely
Take a database backup first. Then delete expired rows in batches rather than in one statement, so you never hold a long lock against live checkout traffic:
DELETE FROM wp_woocommerce_sessions
WHERE session_expiry < UNIX_TIMESTAMP()
LIMIT 1000;
Repeat until it reports zero rows affected. Then reclaim the space:
OPTIMIZE TABLE wp_woocommerce_sessions;
Run all of this at your quietest hour. OPTIMIZE locks the table while it rebuilds.
What not to do
- Do not run TRUNCATE. It removes every session including the carts of people shopping right now. On a busy store that is lost orders, not a tidy database.
- Do not use WooCommerce, Status, Tools, Clear customer sessions as a routine fix. It does the same thing: it clears every session, not just the expired ones. It has its uses, but run it knowing the cost and run it at a quiet time.
- Do not delete the rows and stop there. If the cleanup is broken, you have bought a few weeks and the table will be back.
My take: this is a shipped defect, not a maintenance failure
WooCommerce ships a table whose scheduled cleanup filters on a column it did not index. That is the root of it. Every store owner who finds a four gigabyte sessions table is told they should have maintained their database better, when what actually happened is that a recurring job was set up to do a full table scan against live write traffic and was always going to fall over eventually.
My standing advice is to add the index on any store doing real volume, before there is a problem, and to treat a growing sessions table as a symptom to trace rather than a table to empty. The size is information. Deleting it throws away the evidence and leaves the cause in place.
How to fix this on your store
- Back up the database.
- Measure the table size and the expired to total row ratio. Decide which of the three causes you have.
- If most rows are expired, add the index on session_expiry first, so the cleanup is cheap from now on.
- Delete expired rows in batches of a thousand until none remain, at a quiet hour.
- Run OPTIMIZE TABLE to reclaim the space.
- Find out why cleanup stopped. Check whether WP-Cron is disabled without a server cron replacing it, and check the scheduled actions queue for a backlog.
- If the table refills quickly while sales stay flat, look at bot traffic on your add-to-cart and filter URLs.
- Recheck the table in a week. It should stabilise at a size that matches your real traffic.
Get the cause found, not just the symptom cleared
A sessions table this size is usually one of several things quietly broken in the background. A WooCommerce technical review checks the scheduled jobs, the table structure and the traffic pattern together, which is how you stop it recurring. If the store is slow and you are not sure where the time is going, page speed optimisation starts from measurement instead of guesswork.
Related reading: when filter URLs and bot traffic overload your server, and what to investigate before adding more cache.
Frequently asked questions
Can I delete the wp_woocommerce_sessions table?
Do not delete or truncate the table. It holds live cart and session data, so emptying it removes the carts of everyone currently shopping. Delete only rows where session_expiry is in the past, in batches, after taking a backup. The table itself must stay, because WooCommerce recreates and uses it continuously.
Why is my WooCommerce sessions table so large?
Almost always because the scheduled cleanup stopped running, usually because WP-Cron is disabled with no server cron replacing it, or the scheduled actions queue is jammed. Bot traffic hitting add-to-cart URLs also inflates it, since every request from a new client creates a session row. Check the ratio of expired rows to total rows to tell which you have.
Does a large sessions table slow down WooCommerce?
Yes, and usually across the whole store rather than just at checkout. The bloated table crowds the InnoDB buffer pool, pushing out the product and order data MySQL needs on every page load. The cleanup job also scans the entire table because session_expiry is not indexed by default, which can cause lock contention against live checkout writes.




