Database » wp_actionscheduler_actions & wp_actionscheduler_logs tables

wp_actionscheduler_actions & wp_actionscheduler_logs tables

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 image - wp_actionscheduler_actions & wp_actionscheduler_logs tables icon and under Table optionsStorage engine select MyISAM then click the Go button.

See also  Use Regex with WP CLI to 🔎 Search & Replace in Database
image 1 - wp_actionscheduler_actions & wp_actionscheduler_logs tables

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.

woocommerce scheduled actions - wp_actionscheduler_actions & wp_actionscheduler_logs tables

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;
}

Was this post helpful?

1 thought on “wp_actionscheduler_actions & wp_actionscheduler_logs tables”

Leave a Comment

I enjoy constructive responses and professional comments to my posts, and invite anyone to comment or link to my site.

Recommended