WooCommerce plugin uses the wp_actionsscheduler_actions table in the database to log scheduled actions such as cron’s running, product synchronization, upgrade, etc. These actions should be deleted once they are executed but this doesn’t always happen, in most cases, this table uses an InnoDB database engine with a row-level locking feature meaning that multiple queries can be run simultaneously in the table.
For big traffic websites or websites that sync their products with another site, this becomes a problem because logs cant be deleted if another query is running, and they are kept forever.
Therefore, as the simplest solution, I recommend setting MyISAM database engine for the wp_actionsscheduler_actions table so that only one query can be run in the table, meaning that all other actions have to wait for the first one to finish.
This is of course slower, but will definitely delete logs from the table and stop it from growing GB’s in size.
To change the table engine from InnoDB to MyISAM navigate to the table in PHPMyAdmin then click on the icon and under Table options → Storage engine select MyISAM then click the Go button.
Another solution is to use SQL to remove all logs left by the WP-Cron with the status “failed“, “canceled” and “complete“. These can be seen from the WooCommerce → Status → Scheduled Actions page.
The following SQL command will remove all rows from the table wp_actionscheduler_actions that contain these statuses:
DELETE FROM `wp_actionscheduler_actions` WHERE `status` IN ('complete','failed','canceled')
To remove wp_actionscheduler_logs simply empty the table or run the following command:
TRUNCATE `wp_actionscheduler_logs`
Logs are usually automatically removed from the wp_actionscheduler_logs table 30 days after the creation. To change this value to for example 1 week, add the following snippet to the beginning of your active theme’s functions.php file.
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;
}
Thank you very much, a quarter of a million records were blocking a site migration in the action log and this solved it.
I run the “DELETE FROM `wp_actionscheduler_actions` WHERE `status` IN (‘complete’,’failed’,’canceled’)” from “wp_actionscheduler_actions” and i could not access my admin this is the error message am getting “Sorry, you are not allowed to access this page.”
When i check the error log this is what i saw “[01-Aug-2024 01:12:09 UTC] WordPress database error Deadlock found when trying to get lock; try restarting transaction for query INSERT INTO `wptw_options` (`option_name`, `option_value`, `autoload`) VALUES (‘image_optimizer_compression_level’, ‘lossy’, ‘auto’) ON DUPLICATE KEY UPDATE `option_name` = VALUES(`option_name`), `option_value` = VALUES(`option_value`), `autoload` = VALUES(`autoload`) made by do_action(‘admin_init’), WP_Hook->do_action, WP_Hook->apply_filters, ImageOptimization\Modules\Settings\Module->register_options, add_option”