In my module I'm creating new permissions that I want by default also assigned to the Drupal admin user.

I know how to assign new permissions to a role, but I don't know how to get the Drupal administrator role id. In the database the rid for administrator is 3, but can I rely on that being always the case? I'm using Drupal 7.

  • If I am not mistaken, new modules always apply permissions to the administrator role defined on admin/config/people/accounts. But only if you install the module. So disabling, uninstalling and installing should grant the the permissions to the admin user as well. (Or if someone else installs the module fresh.) Commented Dec 8, 2016 at 20:40

2 Answers 2


unless you install Drupal in your custom installation profile and modify the administrator role there, the rid or administrator will be always 3.
Or you could just do a db_query() on role table to return the rid of administrator as:

$result = db_query("SELECT rid FROM {role} where name like :id",array(':id' => 'administrator'));
$admin_rid = $result->fetchField(0);

Consider that the administrator role may have a different name than administrator or may have a different role ID.

Drupal 7 has a configuration available at Account Settings page: Administrator role

Administrator role

The value is stored in variable named user_admin_role.

$admin_rid = variable_get('user_admin_role');

After getting the role ID, you can do pretty much anything you need with it.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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