0

I have a content type in my Drupal 8 instance and having more than 2 millions (20 lakhs) node and want to delete those node, tried many things but nothing helps, either HTTP 500 error occur or Website encounter an error message came. Need help please suggest some workable solution. Methods I have tried so far are :-

  1. Using module - Delete All
  2. Devel generate and delete method Article.
  3. Using query

     $result = \Drupal::entityQuery('node')
      ->condition('type', 'my_content_type_name')
      ->execute();
    entity_delete_multiple('node', $result);
    

Please Help!!!

  • Have you tried drush genc 0 --kill --types=my_content_type? – leymannx Sep 7 at 5:26
  • my drush is not working I don't know why, drush is giving a long error message. – Pratish Kumar Jha Sep 7 at 6:01
  • I've tired this -> $types = array('my_content_type'); $nids_query = db_select('node', 'n') ->fields('n', array('nid')) ->condition('n.type', $types, 'IN') ->range(0, 5000) ->execute(); $nids = $nids_query->fetchCol(); entity_delete_multiple('node', $nids); this code delete 5000 nodes but if I increase this number to 10000 then again HTTP 500 error occur. – Pratish Kumar Jha Sep 7 at 6:03
  • You need to batch process this code to process like only 1000 nodes at once. Look for Batch API. And get your Drush up and running again. – leymannx Sep 7 at 6:09
  • 1
    Here this one looks good, you can raise the number of the chunk from 50 to 1000: openwritings.net/pg/drupal/… – leymannx Sep 7 at 6:21

Your Answer

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

Browse other questions tagged or ask your own question.