Example usage: implementing inherited privileges
The following steps show how user Joe enables inheritance of privileges on a given schema so other users can access tables in that schema.
The following steps show how user Joe enables inheritance of privileges on a given schema so other users can access tables in that schema.
-
Joecreates schemaschema1, and creates tabletable1in it:=>\c - Joe You are now connected as user Joe => CREATE SCHEMA schema1; CRDEATE SCHEMA => CREATE TABLE schema1.table1 (id int); CREATE TABLE -
Joegrants USAGE and CREATE privileges onschema1toMyra:=> GRANT USAGE, CREATE ON SCHEMA schema1 to Myra; GRANT PRIVILEGE -
Myraqueriesschema1.table1, but the query fails:=>\c - Myra You are now connected as user Myra => SELECT * FROM schema1.table1; ERROR 4367: Permission denied for relation table1 -
JoegrantsMyraSELECT ON SCHEMAprivileges onschema1:=>\c - Joe You are now connected as user Joe => GRANT SELECT ON SCHEMA schema1 to Myra; GRANT PRIVILEGE -
JoeusesALTER TABLEto include SCHEMA privileges fortable1:=> ALTER TABLE schema1.table1 INCLUDE SCHEMA PRIVILEGES; ALTER TABLE -
Myra's query now succeeds:=>\c - Myra You are now connected as user Myra => SELECT * FROM schema1.table1; id --- (0 rows) -
Joemodifiesschema1to include privileges so all tables created inschema1inherit schema privileges:=>\c - Joe You are now connected as user Joe => ALTER SCHEMA schema1 DEFAULT INCLUDE PRIVILEGES; ALTER SCHEMA => CREATE TABLE schema1.table2 (id int); CREATE TABLE -
With inherited privileges enabled,
Myracan querytable2withoutJoehaving to explicitly grant privileges on the table:=>\c - Myra You are now connected as user Myra => SELECT * FROM schema1.table2; id --- (0 rows)