Stale batches

Last updated on
1 October 2026

The Abandoned batch jobs task removes old batch jobs from the batch table, plus the leftover drupal_batch:* queues they leave behind. It works on every Drupal site.

When you need it

Every batch operation (a bulk content update, an import, drush updatedb, a Views bulk operation...) is stored in the batch table while it runs. Core has a method for purging old rows, BatchStorage::cleanup(), but in the Drupal 11.4 releases we checked nothing calls it, so the table only ever grows. Batches can hold large serialized payloads. Each batch set also gets a queue named drupal_batch:{batch id}:{set}, which stays behind if the batch never finished.

On a real site this task found 209 abandoned batches going back 17 months.

What it removes

  • Batch jobs older than the configured age (default 10 days, the same as core's own cleanup method), oldest first. Their queues go with them.
  • Leftover batch queues: items in drupal_batch:* queues whose batch job no longer exists.

Queues that aren't batch queues are never touched. A site that has never run a batch (so has no batch or queue table yet) simply has nothing to remove.

Configuration

Set the age at Configuration » System » Cleanup, under Abandoned batch jobs: older than (days). Anything below 1 day is treated as 1, so a batch that is still running is never removed, whatever the setting says.

Running it

drush cleanup:run --task=stale_batches --dry-run
drush cleanup:run --task=stale_batches

It also runs in the cron sweep if enabled (on by default).

Backups

Before deleting, the run saves the batch rows and every item in the queues it removes. Queues are removed with core's own batch queue class, the one the Batch API uses itself. Undo a run with drush cleanup:restore {backup-id}.

Help improve this page

Page status: No known problems

You can: