I was recently asked to investigate a warning about low disk space because of the database growing. The culprit turned out to be the cache_form table, which apparently had reached close to a couple of GBs in size. Turns out that this is a known/common problem:
cache_form is never cleared on some sites (D7 core issue, reported in March 2012, still open at the time of writing)
https://drupal.stackexchange.com/questions/69803/cache-form-table-size-i...
The
cache_formtable is a little funny, and behaves in a slightly different manner than other cache tables.If you take a look at
drupal_flush_all_caches()you will see thatcache_formisn't cleared. This is to protect in-progress forms from being nuked.The
system_cron()function does take care of pruning out old data fromcache_formalong with the other cache tables.You really should run cron on all Drupal sites...
In my case, cron was running just fine. The cache_form table was simply not being cleared, and it had reached 9000+ rows. It was just spambots
While troubleshooting, I had to "manually" fix things by truncating the cache_form table (ssh -> mysql commands and queries etc.). This seems to be a far too common problem for us to ignore. We should be providing the common Joe with the tools to perform cleanup via the UI.
Here's a few thoughts/suggestions:
- Provide a way to see db tables sorted by size in the admin UI (site status page, db info section)
- Allow truncating the
cache_formtable via a dedicated "Flash form caches" submenu, under the admin menu "Flash all caches" ("Flash all caches" is left as is though, still excluding thecache_form). - Add a new "Clear form caches" button in
/admin/config/development/performance. Make it adanger/red button, have help text explaining why. - Ensure that both the admin menu item and the button in the performance page have a confirmation dialog.
drushcommand
Here's a D7 contrib module that does most of these things: https://www.drupal.org/project/optimizedb
There is well-known issue with fast-growing table cache_form. This table stores Drupal form cache and it isn’t cleared when you flush all cache or run cron. Also you can struggle with problem of fragmentation with InnoDB tables on active delete/insert operations. This module provide functionality to solve this problem. Also its provide additional tools for maintenance database.
...this module seems to have originated by https://www.drupal.org/project/db_cache_clear
The project is originated by issues #2382227: Add option to clear cache_form expired records and #2409377: Add option to clear all cache tables using 1 button and by cron
Update: Module OptimizeDB should solve the above issues.
Perhaps related: * https://github.com/backdrop/backdrop-issues/issues/1470 [PS] Use signatures instead of the form cache * https://github.com/backdrop/backdrop-issues/issues/3833 [PS] Do not make entries in "cache_form" when viewing forms that use #ajax['callback']
Recent comments
Thanks!! Easiest for me to just give permission for anon users to see the admin theme. That worked. It's just for this one page.
Link field in a Content Type is malformed for annonymous user- Permission issue?
It looks like the screenshot of what you show it should look like is the admin theme whereas what they see is the front end theme. By default, such users won't have permissions to see the...
Link field in a Content Type is malformed for annonymous user- Permission issue?
I've added a new recipe. The recipe has no PHP code. It has two module dependencies (one of those depends on another contrib module and both depend on core modules that are normally enabled)...
The Future of Configuration Recipes for Backdrop CMS