My site has about 200 000 nodes. When I want to delete let say 200 nodes it takes about 2hr. I have also installed commerce module, views and a lot of the usual modules. What can I do to speed things up?

  • How are you deleting your nodes right now? From the admin/content screen? – Cyclonecode Mar 17 '17 at 11:59
  • Run it on better equipment; other than that you'll probably need to dig into the core code and optimise anything you can to mitigate the lack of resources – Clive Mar 17 '17 at 12:01
  • Running entity_delete ops is heavy if you have a lot of things acting on this event like contrib code or rules. – Kevin Mar 17 '17 at 15:58

Usually I use 2 approach from the command line. If you call a page from the browser to accomplish the task this will use more time and resources.

1. You can create your own module named drush_delete

Inside the drush_delete.drush.inc file put this code:

 * @file
 * The Drush Delete drush commands.

* Implements hook_drush_command().
function drush_delete_drush_command() {
  $items['node-delete'] = array(
    'description' => dt("Delete nodes."),
    'aliases' => array('nd'),
    'arguments' => array(
      'nids' => dt('The nids of the nodes to delete'),
    'examples' => array(
      'drush node-delete 1' => dt('Delete the node with nid = 1.'),
      'drush node-delete 1 2 3' => dt('Delete the nodes with nid = 1, 2 and 3.'),

  return $items;

 * Callback for the node-delete command
function drush_drush_delete_node_delete() {
  $nids = func_get_args();
  $nids = array_filter($nids, 'is_numeric');
  $nids = array_map('intval', $nids);
  $nids = array_unique($nids);
  $nids = array_values($nids);
  $cant = count($nids);

  if ($cant > 0) {

    drush_print(dt("Deleted nodes:"));
    drush_print(implode(' ', $nids));
  else {
    drush_set_error('DRUSH_ERROR_CODE', dt("You must enter at least one nid"));

Install the module, run drush cc drush to clear the drush cache and use the command like this:

To delete a node use:

drush node-delete 1
drush nd 1

To delete multiple nodes use:

drush node-delete 1 2 3
drush nd 1 2 3

EDIT: I just remeber that I have a collection of drush commands in github at https://github.com/adrian-cid/drush_commands.

2. You can use the Drush Entity module

Deleting node with nid 1 and 2

drush entity-delete node 1 2

Deleting all the nodes:

drush entity-delete node

Deleting all the articles nodes:

drush entity-delete node --bundles=article
  • This is a better approach. With so many nodes, I would probably create a VBO action "mark node to be deleted" - which creates a job via QueueAPI, and the drush command pulls from that queue and deletes each flagged node. Then set up a cron job for every X minutes to call that function. – Kevin Mar 17 '17 at 17:27
  • @Kevin nice approach, can you write an answer about how to do this please, I'm interested in test it. – Adrian Cid Almaguer Mar 17 '17 at 17:31
  • 1
    Not sure of code offhand, but, if you can create a custom VBO action, that action will create jobs in the job queue via QueueAPI. Every job that is processed contains a callback, which is where you would delete the node. See this article for an example: metaltoad.com/blog/… – Kevin Mar 17 '17 at 17:37

I think you should be able to speed things up by using node_delete_multiple(). You can create a simple script in your drupal installation path which then can be called from the browser:

/** bootstrap drupal **/
define('DRUPAL_ROOT', getcwd());
require_once 'includes/bootstrap.inc';

// array holding all nids of the nodes you would like to delete
$nids = array(

// make sure the script does not timeout


Of course you need to supply the nids for all nodes that you wish to delete.

The fastest way would also be to run this script from the command line:

php delete-nodes.php
  • this is in a page and the page will be called from the browser? – Adrian Cid Almaguer Mar 17 '17 at 15:01
  • Yes this would be put in a stand alone file placed in the root of the drupal installation. Of course all nids must be added and I'm not sure this would really would speed things up, but I think it is worth a try. – Cyclonecode Mar 17 '17 at 15:09
  • I think that you need to add this info in yout question and how run the script from the command line because if you run this from the broswer will be more slow that from the command line. – Adrian Cid Almaguer Mar 17 '17 at 15:26
  • @AdrianCidAlmaguer - It is an answer not a question =) And you don't need to run it from the command line. – Cyclonecode Mar 17 '17 at 15:28
  • @ yes is true in your answer, sorry, just I think that you can call your script from the command line and this will be better, is just a suggestion. – Adrian Cid Almaguer Mar 17 '17 at 15:41

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.