Reducing Table Size of WooCommerce Scheduler Actions and Logs using phpMyadmin
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.