Rebuild node permissions table on large sites with many nodes

Every now and again the node permissions table on a Drupal site can go out of whack. The result is that some users may get an accessed denied message when trying to access pages.

This is fairly easy to fix on a "normal size" website. You simply go to admin -> content -> post settings and click "Rebuild permissions".

However, this does not always work on a partcularly large Drupal based website. I have tried this on a site with around 11,000 nodes and it times out, giving me a page not found error.

One solution is to use a custom script to rebuild the node permissions one node at a time. I found this script on

Thanks to enboig for the script.

I have used it on the site with 11,000 nodes and it works like a treat. Although it does take a long time to run. In this case, it took several hours. But at least it worked!



I want to run the script on my site. Could you help me where shall I keep the script in drupal?

Thnaks in advance.


Blair Wadman's picture

Hi Sagar,

You need to put the script in your Drupal root directory (the same directory that has the main index.php page).

I have noticed that the link that I posted no longer takes you direct to the comment with the code for the script. It has moved into the body of the post. It is now under "Node Access" under "WSODs Due to Specific Modules".

When I get a chance I'll post the script here as well to make it easier to find.

Run this code with firebug(remove php tags) or put it in node and click preview(choose php as input format):

db_query("DELETE FROM {node_access}");

This has solved me many problems when the rebuilding gets
stuck etc.

This script saved my tail... Thank you Thank you

Note that there is still a hardcoded time limit in node.module :


You can also work around this if you have a newer drush version with the following:
PHP_OPTIONS='-d disable_functions=set_time_limit -d max_execution_time=0 -d memory_limit=1024M' drush php-eval 'node_access_rebuild();'

New comments for this tutorial have been turned off.