HiveBrain v1.2.0
Get Started
← Back to all entries
snippetsqlModerate

Postgresql: How to add a role that inherits from another?

Submitted by: @import:stackexchange-dba··
0
Viewed 0 times
postgresqlrolethatanotherinheritshowfromadd

Problem

Pretty cut and dry, I am just a total noob. Is there a way to make a given role inherit from another?

Solution

CREATE ROLE doe LOGIN INHERIT;
CREATE ROLE sales NOINHERIT;
CREATE ROLE marketing NOINHERIT;
GRANT sales to doe;
GRANT marketing to sales;


If you connect to PostgreSQL as doe, you will have privileges of doe plus privileges granted to sales, because doe user role has INHERIT attribute. However, you do not have privileges of marketing because the NOINHERIT attribute is defined for the sales user role.

Note:
The role attributes LOGIN, SUPERUSER, CREATEDB, and CREATEROLE can be thought of as special privileges, but they are never inherited as ordinary privileges on database objects are.

Code Snippets

CREATE ROLE doe LOGIN INHERIT;
CREATE ROLE sales NOINHERIT;
CREATE ROLE marketing NOINHERIT;
GRANT sales to doe;
GRANT marketing to sales;

Context

StackExchange Database Administrators Q#60942, answer score: 13

Revisions (0)

No revisions yet.