JulJ
JulJ

Reputation: 127

Postgresql: How to grant permission for set role?

There is user 'test_user1'. SET ROLE Command:

SET ROLE test_user1

returns error:

ERROR:  permission denied to set role "test_user2"

I couldn't find how to grant permission for SET ROLE.

Thanks in advance.

Upvotes: 8

Views: 23092

Answers (2)

Chris Travers
Chris Travers

Reputation: 26454

Supplementing Egor's answer, in PostgreSQL, roles can be inherited or not (INHERIT or NOINHERIT option on the role).

If it is inherited, then GRANT means that you are granting all access that granted role has to the grantee role.

If it is not inherited, then GRANT gives permission to use SET ROLE to switch to that role. In other words, GRANT gives access to the other role, and INHERIT determines whether that access requires a SET ROLE command to work.

Upvotes: 9

Egor Rogov
Egor Rogov

Reputation: 5388

Error message

ERROR: permission denied to set role "test_user2"

implies that the command was

test_user1> SET ROLE test_user2;

, but not SET ROLE test_user1 as you wrote.

If you are trying to set role test_user2 for the user test_user1, grant it:

test_user2> grant test_user2 to test_user1;

Upvotes: 12

Related Questions