Drupal remove deleted fields from database

Install and enable Field SQL norevisions, and use it to delete any revisions you don't need. Also set it to disable revisions for content/entity types that you don't want revisions being made.

Note: For entity content types, drupal will automatically make revisions for each update, but won't allow you to revert to any of these revisions, so this is pretty pointless; plus for very large databases this can degrade performance.

When you delete fields, there are going to be a bunch of tables called field_deleted_data_* and field_deleted_revision​*with just as much data as the original fields you deleted. These will eventually get removed by doing drupal cron runs. However to speed things up, you can increase the number of fields that get processed via:

drush eval "field_purge_batch(5000)"

Note: change 5000 to whatever number. The default may be 500.

To get rid of ghost fields, you can also do this via phpMyAdmin:

DELETE FROM `field_config` WHERE `field_config`.`deleted` = 1;

Once we run the above query, we next want to empty (TRUNCATE) all field_deleted_data_* and field_deleted_revision​* via phpMyAdmin

Simply select all the field_deleted_data_* and field_deleted_revision​*, and then at the bottom "with selected" select "Empty"

Troubleshooting

If you try running drush cron and get an error message: WD cron: Attempting to re-run cron while it is already running., then run the following:

drush --yes vset cron_semaphore 0; drush cron

Tags: Drupal drush