Search code examples
postgresqlrolesql-grant

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.


Solution

  • 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.