I have user 'administrator' with CREATEROLE privileges. I create new user like this:
CREATE USER test_user;
And then i grant privileges to the new user:
GRANT administrator TO test_user;
When i'm logged in as 'administrator', i can create users without a problem, since 'administrator' has the privilege to do it. But for some reason 'test_user' can't create users. When i'm trying it, i get this output:
ERROR: permission denied to create role
Output of \du:
List of roles
Role name | Attributes | Member of
---------------+------------------------------------------------------------+-----------------
administrator | Create role | {}
analyst | | {}
manager | | {}
postgres | Superuser, Create role, Create DB, Replication, Bypass RLS | {}
test_user | | {administrator}
If it was about inheritance,
\duwould showNo inheritanceattribute. I think it might actually be due toCREATEROLEbeing a cluster-wide role attribute that has to be explicitly given and isn't subject to inheritance.So, you can't rely on
test_userhaving alsoadministratorrole, regardless ofinheritsettings on any level. You need to explicitly and independently set the attribute the same way you must've done that foradministratorin the first place:Or
Unless you're ok with manually elevating to
administratorthroughSET ROLE administrator;whenever, astest_useryou need to do something only theadministratorrole has an adequate privilege/attribute for. For thatGRANT administrator TO test_user;is enough.If it was about actual role privilege inheritance as opposed to the the few uninheritable role attributes, here's how role memberships work for those:
To just use
administratorprivileges astest_userwithout switching between them: demoIt's normally the default. The reason why it wouldn't be can be found in the
GRANTcommand doc:And from the
CREATE ROLE...[NO]INHERIT: