Add new comment

Fix for: Could not delete temporary file "temporary://filename.ext" during garbage collection

Submitted by Erik Wegner on

A Drupal website needs a regularly running cron for several update and cleanup tasks. Once the file management taks yields the following message on each run:

Could not delete temporary file "temporary://favicon.png" during         [error]
garbage collection
Could not delete temporary file "temporary://logo64.png" during          [error]
garbage collection
Could not delete temporary file "temporary://logo96.png" during          [error]
garbage collection

The first thing to do is find the records within the database. For example, if your site uses a sqlite3 database, connect to it:

sqlite3 .ht.sqlite

Get a list of all tables:


You will see the table file_managed. That one is interesting. Since this site is a small one, there are not that much files. I can list them all on one page:

select * from file_managed;

Between all the records, there are the three in question:


The first column is the file index column named fid.

A first attempt to remove the file directly through sql commands:

DELETE FROM file_managed WHERE fid = 37;

That brings the error:

Error: no such collation sequence: NOCASE_UTF8

Sqlite requires a special collation here which is provided by Drupal itself. If you do not want to write a custom module at this point, drush comes to your help. Fire it up and open a shell to your Drupal site:

/opt/drush8/drush core-cli

Now, all the Drupal API calls are at your fingertips. Especially this one is easy:


That's it. The next cron run is as quiet as expected.

This question is for testing whether or not you are a human visitor and to prevent automated spam submissions.