The Scheduled Actions that sit in WooCommerce Action Scheduler can get bloated with thousands of actions piling up, just stuck in a failed, canceled, pending or complete state. This can result in very large database tables in particular wp_actionscheduler_actions and wp_actionscheduler_logs tables.
Below find out how to reduce these WooCommerce tables.

Since the states of failed, canceled or complete are already passed, you would be safe to remove them from the wp_actionscheduler_actions table. You can do so in phpMyadmin SQL tab.

Just use the state required in the SQL command…
DELETE FROM `wp_actionscheduler_actions` WHERE `status` = 'canceled'
DELETE FROM `wp_actionscheduler_actions` WHERE `status` = 'failed'
DELETE FROM `wp_actionscheduler_actions` WHERE `status` = 'complete'
For scheduled actions that are pending you can use the same SQL commands as above just change the status to pending, but you would probably leave these to run in time or if they are overdue then run them from within WooCommerce.

wp_actionscheduler_logs Table
If the wp_actionscheduler_logs table is bloated, just empty it.

Or via SQL using :
TRUNCATE wp_actionscheduler_logs
Completed Actions
Completed actions are normally removed by the Action Scheduler after 30 days by default but there is a filter that can change that setting –action_scheduler_retention_period, use it like so in functions.php
add_filter( 'action_scheduler_retention_period', 'wpb_action_scheduler_purge' );
/**
* Change Action Scheduler default purge to 1 week
*/
function wpb_action_scheduler_purge() {
return WEEK_IN_SECONDS;
}
This would reduce the woocommerce table on a permanent basis.
14 comments
Eggs In Langley
Perfect! I had 45K of these completed actions that I was able to remove.
Snusladen.de
This function wpb_action_scheduler_purge returns the value WEEK_IN_SECONDS, as a predefined constant in WordPress that represents the number of seconds in a week (7 days x 24 hours x 60 minutes x 60 seconds)? Or do I need to modify this?
Aodan
This was very very helpful. My database was over 10GB in size for some reason. The SQL command did the job: DELETE FROM `wp_actionscheduler_actions` WHERE `status` = ‘complete’
My server wouldn’t let me process the whole 10GB all at once and kept getting error messages. But I could see that each time it was clearing up about 1GB. So after 11 attempts and error messages, the database is now clear, and a lot of issues I’ve been having have now been cleared up. So once again, thank you for making this post. Cheers.
M.Rusdi
Thank you. Find this information very helpful!
Simone Longato
Thank you! I bought this system on a site that I manage. I then cleaned the database by deleting the lines, because it gave me an error in entering the code.
But now the database certainly weighs less!
A thousand thanks
Shams Uz Zaman
My wordpress website database causing an error of Error establishing a database connection the hosting provider told that wp_actionscheduler_logs of your database table create an issue.
Can I empty that?
Dresuar
it worked for me, Very helpful. thank you very much
Juan Villegas
It is worth to mention another filter: action_scheduler_cleanup_batch_size
The default batch size value is 20, it means that 20 completed tasks are removed from the DB in every clean up.
If your website generate a lot of tasks, maybe a batch size of 20 is not enough, so you can do something like this to increase the value to 100, or whatever you need:
function my_plugin_action_scheduler_cleanup_batch_size($batch_size = 20) {
$batch_size = absint($batch_size);
return max(100, $batch_size);
}
add_filter(‘action_scheduler_cleanup_batch_size’, ‘my_plugin_action_scheduler_cleanup_batch_size’);
Morgan
Added to my list for routine database optimization.
Thank you for this simple useful post
Wesley Carnicle
How can it be re installed if it was deleted
Josh
But why is it happening in the first place??
My webhost limits DBs to 1GB and when this happens, they lock our DB until I empty the table. I need to know what the root cause is. Anyone know?
Nick
Thanks for your post. You can run all 3 quickly with `DELETE FROM `wp_actionscheduler_actions` WHERE `status` IN (‘canceled’, ‘failed’, ‘complete’);`
Scott
Hi, thanks for writing on this topic. I find that every time I update Woocommerce, on nearly every store I have, the database updates never finish on their own, and I discover many pending actions stuck in the scheduler. Is this common? If not, what issues should I be looking for that would cause this?
Brigitte
Thank you so much for this useful contribution. I used it already a few times. Very helpful!